[concurrency-interest] Disposing a BlockingQueue with capacity?

Brian Goetz brian at quiotix.com
Sun Mar 4 17:38:57 EST 2007

See JCiP 7.2.1.

Oliver Pfeiffer wrote:
> How should a BlockingQueue with a fixed capacity be disposed to release all
> waiting submitter threads?
> Assuming we have a black-box service sequentially processing items. The
> items can be submitted to the black-box by 1..n threads in parallel. The box
> uses a LinkedBlockingQueue with a fixed capacity of 10. When the queue
> becomes full there could be more than 10 (e.g. 1000) blocked threads waiting
> to submit further items.
> How can this black-box safely be terminated by releasing all submitter
> threads? Unfortunately the capacity can't be set to infinity after
> construction and a BlockingQueue#clear() does only clear the currently
> queued items. Thus in the example above we will release 10 threads
> (successful submit) but will still have 990 threads blocked.

More information about the Concurrency-interest mailing list