...
The methods notify()
and notifyAll()
of package java.lang.Object
are used to waken waiting thread(s). These methods must be invoked from code that holds the same object lock as the waiting thread(s). The notifyAll()
method wakes up all threads and allows ones whose condition predicate is true to resume execution. Furthermore, if all the threads require whose condition predicate is now true held a specific lock before going into wait state, only one of them will obtain reacquire the lock upon being notified, and the others may, presumably, 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 is not satisfied, the chosen thread may not awaken, defeating the purpose of the notify()
call.
...
- Every condition predicate in every thread waiting on the object is satisfied when waiting thread would be satisfied if a notification is were received by each, independently. Furthermore, all these threads must perform the same set of operations after waking up. In other words, any selected thread is allowed one thread can be selected to wake up and resume for an invocation of
notify()
. - Only one thread must wake up on the notify signal. This is contingent on the condition predicate, in that, only one predicate must fulfill the condition and allow the thread to proceed. Multiple condition predicates in the same statement should be avoided.
- No untrusted code has access to the object being waited on. If untrusted code has access to this object, it can
wait()
on the object and intercept anotify()
call.
...