/** * Wait until all currently running workers stop; no input can be submitted * after calling this method. When this method returns, no worker should be * running. * * @throws InterruptedException */ protected synchronized void waitWorkers() throws InterruptedException { if (buffer_.isEmpty()) // wake up blocked workers if not done already buffer_.offer(poison_pill_); executor_.waitDone(); // remove all poison pills while (buffer_.peek() == poison_pill_) { buffer_.remove(); } }