From d3735e9e584770bb0a0d97321420ff59cbb64ac1 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Sun, 1 Jul 2007 22:04:03 -0600 Subject: [PATCH] add TestThreads.java --- classpath/TestThreads.java | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 classpath/TestThreads.java diff --git a/classpath/TestThreads.java b/classpath/TestThreads.java new file mode 100644 index 0000000000..004e249138 --- /dev/null +++ b/classpath/TestThreads.java @@ -0,0 +1,45 @@ +public class TestThreads { + + public static void main(String[] args) { + TestThreads test = new TestThreads(); + Thread th = new Thread(test); + + try { + synchronized (test) { + th.start(); + test.wait(); + } + } catch (Throwable e) { + e.printStackTrace(); + } + + System.out.println("finished"); + } + + public void run() { + synchronized (this) { + int i = 0; + try { + System.out.println("I'm running in a seperate thread!"); + + final int arrayCount = 64; + final int arraySize = 4; + System.out.println("Allocating and discarding " + arrayCount + + " arrays of " + arraySize + "MB each"); + for (; i < arrayCount; ++i) { + byte[] array = new byte[arraySize * 1024 * 1024]; + } + + long nap = 5; + System.out.println("sleeping for " + nap + " seconds"); + Thread.sleep(nap * 1000); + } catch (Throwable e) { + System.err.println("caught something in second thread after " + i + + " iterations"); + e.printStackTrace(); + } finally { + notifyAll(); + } + } + } +}