net.sf.beanlib.util.concurrent
Class ConcurrentLinkedBlockingQueue<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractQueue<E>
          extended by net.sf.beanlib.util.concurrent.ConcurrentLinkedBlockingQueue<E>
Type Parameters:
E - the type of elements held in this collection
All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, BlockingQueue<E>, Queue<E>
Direct Known Subclasses:
ConcurrentLinkedBoundedBlockingQueue

public class ConcurrentLinkedBlockingQueue<E>
extends AbstractQueue<E>
implements Serializable, BlockingQueue<E>

An unbounded concurrent blocking queue implemented upon ConcurrentLinkedQueue.

Note there is currently no such class in Java 6.

In contrast to LinkedBlockingQueue which is always bounded, a ConcurrentLinkedBlockingQueue is unbounded.

Author:
Hanson Char
See Also:
Serialized Form

Nested Class Summary
protected static class ConcurrentLinkedBlockingQueue.ThreadMarker
           
 
Field Summary
private  ConcurrentLinkedQueue<ConcurrentLinkedBlockingQueue.ThreadMarker> parkq
           
private  ConcurrentLinkedQueue<E> q
           
private static long serialVersionUID
           
 
Constructor Summary
ConcurrentLinkedBlockingQueue()
           
ConcurrentLinkedBlockingQueue(Collection<? extends E> c)
           
 
Method Summary
 int drainTo(Collection<? super E> c)
           
 int drainTo(Collection<? super E> c, int maxElements)
           
 Iterator<E> iterator()
           
 boolean offer(E e)
           
 boolean offer(E e, long timeout, TimeUnit unit)
           
 E peek()
           
 E poll()
           
 E poll(long timeout, TimeUnit unit)
          Retrieves and removes the head of this queue, waiting up to the specified wait time if necessary for an element to become available.
 void put(E e)
           
 int remainingCapacity()
           
 int size()
           
 E take()
          Retrieves and removes the head of this queue, waiting if necessary until an element becomes available.
 
Methods inherited from class java.util.AbstractQueue
add, addAll, clear, element, remove
 
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.concurrent.BlockingQueue
add
 
Methods inherited from interface java.util.Queue
element, remove
 
Methods inherited from interface java.util.Collection
addAll, clear, contains, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

parkq

private final ConcurrentLinkedQueue<ConcurrentLinkedBlockingQueue.ThreadMarker> parkq

q

private final ConcurrentLinkedQueue<E> q
Constructor Detail

ConcurrentLinkedBlockingQueue

public ConcurrentLinkedBlockingQueue()

ConcurrentLinkedBlockingQueue

public ConcurrentLinkedBlockingQueue(Collection<? extends E> c)
Method Detail

iterator

public Iterator<E> iterator()
Specified by:
iterator in interface Iterable<E>
Specified by:
iterator in interface Collection<E>
Specified by:
iterator in class AbstractCollection<E>

size

public int size()
Specified by:
size in interface Collection<E>
Specified by:
size in class AbstractCollection<E>

offer

public boolean offer(E e)
Specified by:
offer in interface BlockingQueue<E>
Specified by:
offer in interface Queue<E>

peek

public E peek()
Specified by:
peek in interface Queue<E>

poll

public E poll()
Specified by:
poll in interface Queue<E>

take

public E take()
       throws InterruptedException
Retrieves and removes the head of this queue, waiting if necessary until an element becomes available.

Specified by:
take in interface BlockingQueue<E>
Returns:
the head of this queue
Throws:
InterruptedException - if interrupted while waiting

poll

public E poll(long timeout,
              TimeUnit unit)
       throws InterruptedException
Retrieves and removes the head of this queue, waiting up to the specified wait time if necessary for an element to become available.

Specified by:
poll in interface BlockingQueue<E>
Parameters:
timeout - how long to wait before giving up, in units of unit. A negative timeout is treated the same as to wait forever.
unit - a TimeUnit determining how to interpret the timeout parameter
Returns:
the head of this queue, or null if the specified waiting time elapses before an element is available
Throws:
InterruptedException - if interrupted while waiting

put

public void put(E e)
         throws InterruptedException
Specified by:
put in interface BlockingQueue<E>
Throws:
InterruptedException

offer

public boolean offer(E e,
                     long timeout,
                     TimeUnit unit)
              throws InterruptedException
Specified by:
offer in interface BlockingQueue<E>
Throws:
InterruptedException

remainingCapacity

public int remainingCapacity()
Specified by:
remainingCapacity in interface BlockingQueue<E>

drainTo

public int drainTo(Collection<? super E> c)
Specified by:
drainTo in interface BlockingQueue<E>

drainTo

public int drainTo(Collection<? super E> c,
                   int maxElements)
Specified by:
drainTo in interface BlockingQueue<E>