|
|
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
|