I learned that calling an Object's wait()
method will release the object monitor, if present.
But I have some questions regarding calling notify()
on this object by another thread:
(when) will the waiting thread wake up, if another (a 3rd) thread owns the object monitor in the meanwhile?
will the waiting thread wake up, if a 3rd thread called wait()
on this object?
is it possible to determine if a thread is waiting for notifying a particular object (java 1.4/java 5)
What's happening if wait()
will be called in the finalize()
method?
notify
will wake one thread waiting on the monitor. Unless and until the monitor is unowned, no thread waiting can run; wait() must be called in a synchronized block and so the lock must be held to continue running that block.notifyAll
to give all threads a chance to wake.