I\'m looking for a way to block until a BlockingQueue is empty.
I know that, in a multithreaded environment, as long as there are producers putting items in
Your use case should be quite special because most typically you would only want to block the producer when the queue is full, but not wait until it is empty.
Anyway, this is doable. I believe that spinning until isEmpty returns true is not THAT inefficient because the producer will be locally spinning, i.e., will be accessing its own cache, not banging the bus. It will however be consume CPU time as the thread remains schedulable. But local spinning is definitely the easier way. Otherwise I see two options:
wait + notify like @niculare suggested