go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  Does notifyAll() Really Wake Up All Threads?
 
Subject: Does notifyAll() Really Wake Up All Threads?
Author: EricJ
In response to: notify() vs notifyAll() -- code examples
Posted on: 02/24/2007 01:52:10 AM

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.


     

    > On 02/24/2007 01:50:30 AM EricJ wrote:


    notify()
    Wakes up a single thread that is waiting on this object's monitor. If any threads are waiting on this object, one of them is chosen to be awakened. The choice is arbitrary and occurs at the discretion of the implementation. A thread waits on an object's monitor by calling one of the wait methods.

    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.





    References:

  •  


     
    Powered by ForumEasy © 2002-2022, All Rights Reserved. | Privacy Policy | Terms of Use
     
    Get your own forum today. It's easy and free.