Condition synchronization in Java
Condition synchronization in Java
Java provides only one condition queue per monitor (or actually per object since any object may have a monitor lock associated with it). The following methods are provided by class Object (from which all other classes are derived).
public final void notify()
Wakes up a single thread that is waiting on this object's monitor queue.
public final void notifyAll()
Wakes up all threads that are waiting on this object's monitor queue.
public final void wait() throws InterruptedException
Waits to be notified by another thread. When notified, the thread must
wait to reacquire the monitor before resuming execution.
These operations fail if called by a thread which does not currently “own” the monitor ie. has acquired the monitor lock by executing a synchronized method or statement.