<<< Synchronized blocks in instance methods | Index | Example: wait() -- notifyAll() >>> |
wait() notify() notifyAll()
Code that waits on a condition:
// if there are no orders ready, wait while ( orderQueue.count() == 0 ) { try { wait(); } catch ( InterruptedException e ) { } }
Another thread satisfies the condition and notifies other threads:
// add an order to the queue orderQueue.add( order ); // notify other threads notifyAll();
<<< Synchronized blocks in instance methods | Index | Example: wait() -- notifyAll() >>> |