I\'m looking for a way to block until a BlockingQueue is empty.
BlockingQueue
I know that, in a multithreaded environment, as long as there are producers putting items in
A simple solution using wait() and notify():
wait()
notify()
// Producer: synchronized(queue) { while (!queue.isEmpty()) queue.wait(); //wait for the queue to become empty queue.put(); } //Consumer: synchronized(queue) { queue.get(); if (queue.isEmpty()) queue.notify(); // notify the producer }