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