[concurrency-interest] MRULinkedBlockingQueue

Mike Quilleash mike.quilleash at subexazure.com
Wed Apr 18 05:23:27 EDT 2007

Hi all,
Has anyone seen or comes across an collection implementation that has
the following characteristics.
1) Concurrent
2) Maintains insertion order (for iteration)
3) Capacity bound
4) An add() that would cause the capacity to exceed the limit would
remove the oldest element and add a new one.
I thought of the following extension to LinkedBlockingQueue which simply
loops in add() trying to offer() and removing an element from the queue
if the offer() fails.
public class MRULinkedBlockingQueue< T > extends LinkedBlockingQueue< T
    public MRULinkedBlockingQueue( int capacity )
        super( capacity );
    public boolean add( T o )
        for ( ;; )
            // try and offer the element
            if ( offer( o ) )
                return true;
            // remove the head of the queue to make room if the offer

Any comments appreciated.

 This e-mail is bound by the terms and conditions described at http://www.subexazure.com/mail-disclaimer.html

-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20070418/ca3910e2/attachment.html 

More information about the Concurrency-interest mailing list