1 // Many threads join a single thread.
3 class Sleeper implements Runnable
7 public Sleeper(int num)
14 System.out.println("sleeping");
19 catch (InterruptedException x)
21 System.out.println("sleep() interrupted");
23 System.out.println("done");
27 class Joiner implements Runnable
31 public Joiner(Thread t)
40 long start = System.currentTimeMillis();
41 join_target.join(2000);
42 if ((System.currentTimeMillis() - start) > 1900)
43 System.out.println("Error: Join timed out");
45 System.out.println("ok");
47 catch (InterruptedException x)
49 System.out.println("join() interrupted");
55 public class Thread_Join
57 public static void main(String[] args)
59 Thread primary = new Thread(new Sleeper(1));
61 for (int i=0; i < 10; i++)
63 Thread t = new Thread(new Joiner(primary));