Communicating with Objects by Waiting and Notifying


  • The wait() method lets a thread say, "there's nothing for me to do now, so put me in your waiting pool and notify me when something happens that I care about." Basically, a wait() call means "wait me in your pool," or "add me to your waiting list."
  • The notify() method is used to send a signal to one and only one of the threads that are waiting in that same object's waiting pool.
  • The notify() method can NOT specify which waiting thread to notify.
  • The method notifyAll() works in the same way as notify(), only it sends the signal to all of the threads waiting on the object.
  • All three methods—wait(), notify(), and notifyAll()—must be called from within a synchronized context! A thread invokes wait() or notify() on a particular object, and the thread must currently hold the lock on that object.