wait() should be called from a synchronized method . RHE says the same is also true for the notify() method. But Bill Brogden in Exam Cram says that it is true ONLY for wait(). What about notifyall()?
Shailendra Bade<BR>Mumbai, India<BR>Mail to: bades@vsnl.com
Bill Brogden writes in Exam Cram on page 177 that "...your calls to wait or notify or notifyAll should be in synchronized code blocks." This is correct. Otherwise, an IllegalMonitorStateException could be thrown if a different thread (not the who made the wait() call) tries to notify() or notifyAll().
I think wait() notify(), notifyAll() should be executed by synchronizing on same lock. The threads may be different, as a different thread will notify a waited thread.
This looks like a job for .... legal tender! It says so right in this tiny ad:
a bit of art, as a gift, that will fit in a stocking