Java Quick Reference
  Language Fundamentals
  Operators and Assignments
  Flow Control and Exceptions
  Declarations and Access Control
  Garbage Collection
  Overloading and Overriding
  Threads
  The java.lang Package
  The java.util Package
  The java.awt Package
  The java.io Package
  References
  Miscellaneous Notes
  Tips & Traps
  Mock Exams

Threads - notify() and notifyAll() methods

  • the notify() and notifyAll() methods are defined in the Object class
  • they can only be used within synchronized code
  • notify() wakes up a single thread which is waiting on the object's lock
  • if there is more than one thread waiting, the choice is arbitrary ie there is no way to specify which waiting thread should be re-awakened
  • notifyAll() wakes up ALL waiting threads; the scheduler decides which one will run
  • if there are no waiting threads, the notifys are forgotten
  • only notifications that occur after a thread has moved to wait state will effect it; earlier notifies are irrelevant
Overview Thread Class Runnable Interface Thread States Scheduling Ending a Thread
  Execution Synchronization Locking Protocols synchronized keyword wait() notify(), notifyAll()
  Thread Mechanics