2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / testsuite / libjava.lang / Thread_Join.java
blob711b05cf0f8a415fb9edda60e0bfe58663388d8d
1 // Many threads join a single thread.
2 // Origin: Bryce McKinlay <bryce@albatross.co.nz>
4 class Sleeper implements Runnable
6 int num = -1;
8 public Sleeper(int num)
10 this.num = num;
13 public void run()
15 System.out.println("sleeping");
16 try
18 Thread.sleep(500);
20 catch (InterruptedException x)
22 System.out.println("sleep() interrupted");
24 System.out.println("done");
28 class Joiner implements Runnable
30 Thread join_target;
32 public Joiner(Thread t)
34 this.join_target = t;
37 public void run()
39 try
41 long start = System.currentTimeMillis();
42 join_target.join(2000);
43 if ((System.currentTimeMillis() - start) > 1900)
44 System.out.println("Error: Join timed out");
45 else
46 System.out.println("ok");
48 catch (InterruptedException x)
50 System.out.println("join() interrupted");
56 public class Thread_Join
58 public static void main(String[] args)
60 Thread primary = new Thread(new Sleeper(1));
61 primary.start();
62 for (int i=0; i < 10; i++)
64 Thread t = new Thread(new Joiner(primary));
65 t.start();