I have been looking up information about threads and I am a little confused about wait() and notify(). Actually, I am trying to think of a practical situation where you would want to use these function calls. Can anyone help?
Mo Ibrahim
Greenhorn
Joined: Jul 10, 2001
Posts: 28
posted
0
Here you go Kay
i have put the sleep in the main() just to let you see what's going on. After the program has run, you can see the sequence of events happening, how the first two threads are waiting while the third one has completes and lets the other threads run.
netharam ram
Ranch Hand
Joined: Aug 09, 2001
Posts: 202
posted
0
Here is another simpler example for wait() notify(). code: ********************************************** // Without using Synchronization, with priority. class Stwait implements Runnable { String s1="null",s2; int flag=2; Stwait() { Thread t2=new Thread(this,"two"); t2.start(); t2.setPriority(8); Thread t3=new Thread(this,"three"); t3.start(); t3.setPriority(6); } public void run() { synchronized(this) { for (int i=0;i<3;i++) { s2=Thread.currentThread().getName();