Subject: How Do I Know notify() Wake Up which Thread?
Author: EricJ
In response to: Does notifyAll() Really Wake Up All Threads?
Posted on: 02/24/2007 01:53:50 AM
Never. There is no way to determine which of multiple threads is going to grab the only one notification from notify() method. The Java specification doesn't define which thread gets notified. Which thread actually receives the notification varies based on several factors including the implementation of JVM and scheduling mechanism of platform.
>
> On 02/24/2007 01:52:10 AM EricJ wrote:
Yes and no. All the waiting threads will wake up, but they will not be able to proceed until:
1) the current thread that called the notifyAll() method relinquishes its monitor;
2) the awakened threads will compete in the usual manner with any other threads to acquire the monitor;
3) the winner that grabs the monitor proceed and then release its monitor for the rest threads;
4) so on so forth, and only one thread can run at a time since only one thread at a time can own an object's monitor.
References: