The notifyAll() Method
Home ] Up ] The wait() Method ] The notify() Method ] Other wait() Methods ] [ The notifyAll() Method ]

 

 

There are occasions when we'd like to have a number of threads waiting on a monitor. For example, there might be a number of threads capable of doing work as a Consumer. When there is work available, if the Producer calls notifyAll(), it causes all the threads waiting on that monitor to return from their wait():

public final void notifyAll()

Wakes up all threads that are waiting on this object's monitor. A thread waits on an object's monitor by calling one of the wait methods. This method should only be called by a thread that is the owner of this object's monitor.

The notifyAll() method:

  • Throws IllegalMonitorStateException if the current thread is not the owner of this object's monitor.

In general, notifyAll() tends to be safer than relying on notify().

In general, notifyAll() tends to be safer than relying on notify().

 
The page was last updated February 19, 2008