net.sf.beanlib.util.concurrent
Class ConcurrentLinkedBoundedBlockingQueue<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractQueue<E>
net.sf.beanlib.util.concurrent.ConcurrentLinkedBlockingQueue<E>
net.sf.beanlib.util.concurrent.ConcurrentLinkedBoundedBlockingQueue<E>
- Type Parameters:
E
- the type of elements held in this collection
- All Implemented Interfaces:
- Serializable, Iterable<E>, Collection<E>, BlockingQueue<E>, Queue<E>
public class ConcurrentLinkedBoundedBlockingQueue<E>
- extends ConcurrentLinkedBlockingQueue<E>
An bounded concurrent blocking queue implemented upon
ConcurrentLinkedQueue
.
Note there is currently no such class in Java 6.
- Author:
- Hanson Char
- See Also:
- Serialized Form
Methods inherited from interface java.util.Collection |
addAll, clear, contains, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, toArray, toArray |
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
capacity
private final AtomicInteger capacity
putparkq
private final ConcurrentLinkedQueue<ConcurrentLinkedBlockingQueue.ThreadMarker> putparkq
ConcurrentLinkedBoundedBlockingQueue
public ConcurrentLinkedBoundedBlockingQueue(int capacity)
ConcurrentLinkedBoundedBlockingQueue
public ConcurrentLinkedBoundedBlockingQueue(Collection<? extends E> c)
offer
public boolean offer(E e)
- Specified by:
offer
in interface BlockingQueue<E>
- Specified by:
offer
in interface Queue<E>
- Overrides:
offer
in class ConcurrentLinkedBlockingQueue<E>
tryDecrementCapacity
private boolean tryDecrementCapacity()
poll
public E poll()
- Specified by:
poll
in interface Queue<E>
- Overrides:
poll
in class ConcurrentLinkedBlockingQueue<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>
- Overrides:
take
in class ConcurrentLinkedBlockingQueue<E>
- Returns:
- the head of this queue
- Throws:
InterruptedException
- if interrupted while waiting
unparkIfAny
private void unparkIfAny()
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>
- Overrides:
poll
in class ConcurrentLinkedBlockingQueue<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>
- Overrides:
put
in class ConcurrentLinkedBlockingQueue<E>
- Throws:
InterruptedException
offer
public boolean offer(E e,
long timeout,
TimeUnit unit)
throws InterruptedException
- Specified by:
offer
in interface BlockingQueue<E>
- Overrides:
offer
in class ConcurrentLinkedBlockingQueue<E>
- Throws:
InterruptedException
remainingCapacity
public int remainingCapacity()
- Specified by:
remainingCapacity
in interface BlockingQueue<E>
- Overrides:
remainingCapacity
in class ConcurrentLinkedBlockingQueue<E>
drainTo
public int drainTo(Collection<? super E> c)
- Specified by:
drainTo
in interface BlockingQueue<E>
- Overrides:
drainTo
in class ConcurrentLinkedBlockingQueue<E>
drainTo
public int drainTo(Collection<? super E> c,
int maxElements)
- Specified by:
drainTo
in interface BlockingQueue<E>
- Overrides:
drainTo
in class ConcurrentLinkedBlockingQueue<E>