LinkedBlockingDeque

An optionally-bounded {@linkplain java.util.concurrent.BlockingDeque blocking deque} based on linked nodes.

<p> The optional capacity bound constructor argument serves as a way to prevent excessive expansion. The capacity, if unspecified, is equal to {@link Integer#MAX_VALUE}. Linked nodes are dynamically created upon each insertion unless this would bring the deque above capacity.

<p>Most operations run in constant time (ignoring time spent blocking). Exceptions include {@link #remove(Object) remove}, {@link #removeFirstOccurrence removeFirstOccurrence}, {@link #removeLastOccurrence removeLastOccurrence}, {@link #contains contains}, {@link #iterator iterator.remove()}, and the bulk operations, all of which run in linear time.

<p>This class and its iterator implement all of the <em>optional</em> methods of the {@link Collection} and {@link Iterator} interfaces.

<p>This class is a member of the <a href="{@docRoot}/../technotes/guides/collections/index.html"> Java Collections Framework</a>.

@param <E> the type of elements held in this collection

Note: This was copied from Apache Harmony and modified to suit the needs of Commons Pool.

Constructors

this
this()

Creates a {@code LinkedBlockingDeque} with a capacity of {@link Integer#MAX_VALUE}.

this
this(bool fairness)

Creates a {@code LinkedBlockingDeque} with a capacity of {@link Integer#MAX_VALUE} and the given fairness policy. @param fairness true means threads waiting on the deque should be served as if waiting in a FIFO request queue

this
this(int capacity)

Creates a {@code LinkedBlockingDeque} with the given (fixed) capacity.

this
this(int capacity, bool fairness)

Creates a {@code LinkedBlockingDeque} with the given (fixed) capacity and fairness policy.

this
this(Collection!E c)

Creates a {@code LinkedBlockingDeque} with a capacity of {@link Integer#MAX_VALUE}, initially containing the elements of the given collection, added in traversal order of the collection's iterator.

this
this(E[] c)
Undocumented in source.

Members

Functions

clear
void clear()

Atomically removes all of the elements from this deque. The deque will be empty after this call returns.

contains
bool contains(E o)

Returns {@code true} if this deque contains the specified element. More formally, returns {@code true} if and only if this deque contains at least one element {@code e} such that {@code o == e}.

descendingIterator
InputRange!(E) descendingIterator()

{@inheritDoc}

drainTo
int drainTo(Collection!E c)

Drains the queue to the specified collection.

drainTo
int drainTo(Collection!E c, int maxElements)

Drains no more than the specified number of elements from the queue to the specified collection.

getFirst
E getFirst()

{@inheritDoc}

getLast
E getLast()

{@inheritDoc}

getTakeQueueLength
int getTakeQueueLength()

Returns the length of the queue of threads waiting to take instances from this deque. See disclaimer on accuracy in {@link java.util.concurrent.locks.ReentrantLock#getWaitQueueLength(Condition)}.

hasTakeWaiters
bool hasTakeWaiters()

Returns true if there are threads waiting to take instances from this deque. See disclaimer on accuracy in {@link java.util.concurrent.locks.ReentrantLock#hasWaiters(Condition)}.

interuptTakeWaiters
void interuptTakeWaiters()

Interrupts the threads currently waiting to take an object from the pool. See disclaimer on accuracy in {@link java.util.concurrent.locks.ReentrantLock#getWaitingThreads(Condition)}.

iterator
InputRange!(E) iterator()

Returns an iterator over the elements in this deque in proper sequence. The elements will be returned in order from first (head) to last (tail). The returned {@code Iterator} is a "weakly consistent" iterator that will never throw {@link java.util.ConcurrentModificationException ConcurrentModificationException}, and guarantees to traverse elements as they existed upon construction of the iterator, and may (but is not guaranteed to) reflect any modifications subsequent to construction.

offerFirst
bool offerFirst(E e)

{@inheritDoc}

offerFirst
bool offerFirst(E e, Duration timeout)

Links the provided element as the first in the queue, waiting up to the specified time to do so if the queue is full.

offerLast
bool offerLast(E e)

{@inheritDoc}

offerLast
bool offerLast(E e, Duration timeout)

Links the provided element as the last in the queue, waiting up to the specified time to do so if the queue is full.

peekFirst
E peekFirst()
Undocumented in source. Be warned that the author may not have intended to support it.
peekLast
E peekLast()
Undocumented in source. Be warned that the author may not have intended to support it.
pollFirst
E pollFirst()
Undocumented in source. Be warned that the author may not have intended to support it.
pollFirst
E pollFirst(Duration timeout)

Unlinks the first element in the queue, waiting up to the specified time to do so if the queue is empty.

pollLast
E pollLast()
Undocumented in source. Be warned that the author may not have intended to support it.
pollLast
E pollLast(Duration timeout)

Unlinks the last element in the queue, waiting up to the specified time to do so if the queue is empty.

putFirst
void putFirst(E e)

Links the provided element as the first in the queue, waiting until there is space to do so if the queue is full.

putLast
void putLast(E e)

Links the provided element as the last in the queue, waiting until there is space to do so if the queue is full.

remainingCapacity
int remainingCapacity()

Returns the number of additional elements that this deque can ideally (in the absence of memory or resource constraints) accept without blocking. This is always equal to the initial capacity of this deque less the current {@code size} of this deque.

removeFirstOccurrence
bool removeFirstOccurrence(E o)
Undocumented in source. Be warned that the author may not have intended to support it.
removeLastOccurrence
bool removeLastOccurrence(E o)
Undocumented in source. Be warned that the author may not have intended to support it.
size
int size()

Returns the number of elements in this deque.

takeFirst
E takeFirst()

Unlinks the first element in the queue, waiting until there is an element to unlink if the queue is empty.

takeLast
E takeLast()

Unlinks the last element in the queue, waiting until there is an element to unlink if the queue is empty.

toArray
E[] toArray()

Returns an array containing all of the elements in this deque, in proper sequence (from first to last element).

toString
string toString()

{@inheritDoc}

Meta