Cheers,
Roy.
Sun Certified Java Programmer 1.5,
Sun Certified Web Component Developer 5.
"No pain. No Gain"
http://cs.nyu.edu/~rpm319
According to my understanding, notify() will notify only one thread,
Cheers,
Roy.
Sun Certified Java Programmer 1.5,
Sun Certified Web Component Developer 5.
"No pain. No Gain"
http://cs.nyu.edu/~rpm319
Originally posted by Royston Monteiro:
doesnt the same thing happen with notifyAll() as well? both seem to give the same results![]()
Originally posted by Taariq San:
That's right, but the lock is released and the 3 waiting threads each get a turn to lock and release.
Try adding "Thread.sleep(5000);" after wait to make this clearer.
[ June 05, 2008: Message edited by: Taariq San ]
In this code, when notify() is called, all the threads seem to be notified as "after wait()" is printed thrice. How can this be? shouldnt it get printed only once?
Originally posted by Jack Crifer:
Hi.
But in this case,notify() make all the waiting threads wake up too.
Cheers,
Roy.
Sun Certified Java Programmer 1.5,
Sun Certified Web Component Developer 5.
"No pain. No Gain"
http://cs.nyu.edu/~rpm319
Originally posted by Henry Wong:
Basically, this is a *bad* example... The Thread object is used internally to implement the join() method. The join() method will call wait(), until the thread is no longer alive (reported by the isAlive() method). And the thread cleanup code, will call the notifyAll() method on the thread object, once the thread is mark as no longer alive.
Henry
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |