FDO insane profile
[official-gcc.git] / libjava / testsuite / libjava.lang / Thread_Join.java
blob9f7f2fb1590cf5d0a9348269e6f0b8d6563d1f0e
1 // Many threads join a single thread.
3 class Sleeper implements Runnable
5 int num = -1;
7 public Sleeper(int num)
9 this.num = num;
12 public void run()
14 System.out.println("sleeping");
15 try
17 Thread.sleep(500);
19 catch (InterruptedException x)
21 System.out.println("sleep() interrupted");
23 System.out.println("done");
27 class Joiner implements Runnable
29 Thread join_target;
31 public Joiner(Thread t)
33 this.join_target = t;
36 public void run()
38 try
40 long start = System.currentTimeMillis();
41 join_target.join(2000);
42 if ((System.currentTimeMillis() - start) > 1900)
43 System.out.println("Error: Join timed out");
44 else
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));
60 primary.start();
61 for (int i=0; i < 10; i++)
63 Thread t = new Thread(new Joiner(primary));
64 t.start();