[concurrency-interest] ConcurrentLinkedBlockingQueue ?

Doug Lea dl at cs.oswego.edu
Thu Sep 7 07:24:46 EDT 2006

Hanson Char wrote:
> Hi,
> I've been wondering why there is ConcurrentLinkedQueue in Java 5+, but 
> not something like a ConcurrentLinkedBlockingQueue, which would allow 
> the client to block on an empty queue via a "take" method, or block on 
> an empty for a limited time via a "poll" method.

This IS a good thought.

> Please find below an attempt to build such queue on other existing 
> structures.
> Any concurrency problem with these classes ?  Is there a better way ?

This way works, but reduces concurrency by using a single semaphore,
so is a bit less scalable than current LinkedBlockingQueue. However,
there is a path to much better scalability by using the "dual-queue"
approach similar to what we did for Java 6 SynchronousQueue.
My initial intent was to find a way to internally use such
techniques to replace the unbounded case of LinkedBlockingQueue.
But this turns out not to work out too well because of all the
little compatibility problems encountered -- for example, maintaining
the same Serialization form. So it is more likely that we'll
put out a separate ConcurrentLinkedBlockingQueue that will be
preferable to LinkedBlockingQueue unless you need capacity constraints.
Stay tuned for it...


More information about the Concurrency-interest mailing list