...
The notify()
and notifyAll()
methods of package java.lang.Object
are used to wake up waiting thread(s). These methods must be invoked from code that holds the same object lock as the waiting thread(s). The IllegalMonitorStateException
is thrown if the current thread is not the owner of this object's monitor. The notifyAll()
method wakes up all threads and allows threads whose condition predicate is true to resume execution. Furthermore, if all the threads whose condition predicate evaluates to true previously held a specific lock before going into the wait state, only one of them will reacquire the lock upon being notified. Presumably, the other threads will resume waiting. The notify()
method wakes up only one thread and makes no guarantees as to which thread is notified. If the thread's condition predicate doesn't allow the thread to proceed, the chosen thread may resume waiting, defeating the purpose of the notification.
...