How to immediately release threads waiting on a BlockingQueue
问题 Consider a BlockingQueue and a few threads waiting on poll(long, TimeUnit) (possibly also on on take() ). Now the queue is empty and it is desired to notify the waiting threads that they can stop waiting. The expected behaviour is to have either null returned or the declared InterruptedException thrown. Object.notify() won't work for LinkedBlockingQueue as the threads are waiting on an internal lock. Any straightforward way? 回答1: Javadoc for the BlockingQueue suggests a good way: A