[concurrency-interest] Disposing a BlockingQueue with capacity?

Oliver Pfeiffer pfeiffer at tzi.de
Sun Mar 4 07:49:50 EST 2007

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.

Grüße - Regards
Oliver Pfeiffer
ICQ-ID 84320006

More information about the Concurrency-interest mailing list