diff options
author | Bryce McKinlay <bryce@albatross.co.nz> | 2000-03-23 12:35:44 +0000 |
---|---|---|
committer | Bryce McKinlay <bryce@gcc.gnu.org> | 2000-03-23 12:35:44 +0000 |
commit | e8904f655d46ac43f0d859b8c467bb567dcf4775 (patch) | |
tree | b8f3ddf8bdcae58d2eff8369b44d65dcfb4363fb /libjava/testsuite/libjava.lang/Thread_Join.java | |
parent | 8034da37ce34e442aa8e04f3f1618b70b00ed10e (diff) | |
download | gcc-e8904f655d46ac43f0d859b8c467bb567dcf4775.zip gcc-e8904f655d46ac43f0d859b8c467bb567dcf4775.tar.gz gcc-e8904f655d46ac43f0d859b8c467bb567dcf4775.tar.bz2 |
Thread_Wait.java: New file.
2000-03-23 Bryce McKinlay <bryce@albatross.co.nz>
* libjava.lang/Thread_Wait.java: New file.
* libjava.lang/Thread_Sleep.java: New file.
* libjava.lang/Thread_Monitor.java: New file.
* libjava.lang/Thread_Wait.out: New file.
* libjava.lang/Thread_Sleep.out: New file.
* libjava.lang/Thread_Monitor.out: New file.
* libjava.lang/Thread_Interrupt.java: New file.
* libjava.lang/Thread_Wait_2.java: New file.
* libjava.lang/Thread_Wait_2.out: New file.
* libjava.lang/Thread_Wait_Interrupt.java: New file.
* libjava.lang/Thread_Wait_Interrupt.out: New file.
* libjava.lang/Thread_Interrupt.out: New file.
* libjava.lang/Thread_Join.java: New file.
* libjava.lang/Thread_Join.out: New file.
* libjava.lang/Thread_Alive.java: New file.
* libjava.lang/Thread_Alive.out: New file.
From-SVN: r32706
Diffstat (limited to 'libjava/testsuite/libjava.lang/Thread_Join.java')
-rw-r--r-- | libjava/testsuite/libjava.lang/Thread_Join.java | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/libjava/testsuite/libjava.lang/Thread_Join.java b/libjava/testsuite/libjava.lang/Thread_Join.java new file mode 100644 index 0000000..711b05c --- /dev/null +++ b/libjava/testsuite/libjava.lang/Thread_Join.java @@ -0,0 +1,68 @@ +// Many threads join a single thread. +// Origin: Bryce McKinlay <bryce@albatross.co.nz> + +class Sleeper implements Runnable +{ + int num = -1; + + public Sleeper(int num) + { + this.num = num; + } + + public void run() + { + System.out.println("sleeping"); + try + { + Thread.sleep(500); + } + catch (InterruptedException x) + { + System.out.println("sleep() interrupted"); + } + System.out.println("done"); + } +} + +class Joiner implements Runnable +{ + Thread join_target; + + public Joiner(Thread t) + { + this.join_target = t; + } + + public void run() + { + try + { + long start = System.currentTimeMillis(); + join_target.join(2000); + if ((System.currentTimeMillis() - start) > 1900) + System.out.println("Error: Join timed out"); + else + System.out.println("ok"); + } + catch (InterruptedException x) + { + System.out.println("join() interrupted"); + } + } + +} + +public class Thread_Join +{ + public static void main(String[] args) + { + Thread primary = new Thread(new Sleeper(1)); + primary.start(); + for (int i=0; i < 10; i++) + { + Thread t = new Thread(new Joiner(primary)); + t.start(); + } + } +} |