OSDN Git Service

PR libgcj/12656:
[pf3gnuchains/gcc-fork.git] / libjava / testsuite / libjava.lang / Thread_Wait.java
1 // Test basic thread creation and wait/notify functionality.
2 // Origin: Bryce McKinlay <bryce@albatross.co.nz>
3
4 public class Thread_Wait implements Runnable
5 {
6   public static void main(String args[])
7   {
8     new Thread_Wait();
9   }
10   
11   public Thread_Wait()
12   {
13     System.out.println("creating thread");
14     Thread t = new Thread(this);
15     t.start();
16     
17     try
18     {
19       Thread.sleep(100);
20     }
21     catch (Exception x)
22     {
23       System.out.println("exception occurred: " + x);
24     }
25
26     synchronized (this)
27     {
28       System.out.println("notifying other thread");
29       notify();
30     }
31   }
32   
33   public void run()
34   {
35     System.out.println ("new thread running");
36     synchronized (this)
37     {
38       try
39       {
40         wait();
41       }
42       catch (Exception x)
43       {
44         System.out.println("exception occurred: " + x);
45       }
46     }    
47     System.out.println ("thread notified okay");
48   }
49 }