Java: How can a thread wait on multiple objects? Java: How can a thread wait on multiple objects? multithreading multithreading

Java: How can a thread wait on multiple objects?


You are in for a world of pain. Use a higher level abstraction, such as a blocking message queue, from which the thread can consume messages such as 'more bytes available' or 'item added'.


They could all use the same mutex. You consumer is waiting on that mutex, the both other notify on that mutex when the first can proceed.


A thread cannot wait on more than one object at a time.

The wait() and notify() methods are object-specific. The wait() method suspends the current thread of execution, and tells the object to keep track of the suspended thread. The notify() method tells the object to wake up the suspended threads that it is currently keeping track of.

Useful link : Can a thread call wait() on two locks at once in Java (6) ?