LinkedBlockingQueue

An optionally-bounded {@linkplain BlockingQueue blocking queue} based on linked nodes. This queue orders elements FIFO (first-in-first-out). The <em>head</em> of the queue is that element that has been on the queue the longest time. The <em>tail</em> of the queue is that element that has been on the queue the shortest time. New elements are inserted at the tail of the queue, and the queue retrieval operations obtain elements at the head of the queue. Linked queues typically have higher throughput than array-based queues but less predictable performance in most concurrent applications.

<p>The optional capacity bound constructor argument serves as a way to prevent excessive queue 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 queue above capacity.

<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}/java.base/java/util/package-summary.html#CollectionsFramework"> Java Collections Framework</a>.

@author Doug Lea @param (E) the type of elements held in this queue

Constructors

this
this()

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

this
this(int capacity)

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

this
this(Collection!(E) c)

Creates a {@code LinkedBlockingQueue} 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.

Members

Classes

Node
class Node(E)

Linked list node class.

Functions

add
bool add(E e)
Undocumented in source. Be warned that the author may not have intended to support it.
clear
void clear()

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

contains
bool contains(E o)

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

drainTo
int drainTo(Collection!(E) c)

@throws UnsupportedOperationException {@inheritDoc} @throws ClassCastException {@inheritDoc} @throws NullPointerException {@inheritDoc} @throws IllegalArgumentException {@inheritDoc}

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

@throws UnsupportedOperationException {@inheritDoc} @throws ClassCastException {@inheritDoc} @throws NullPointerException {@inheritDoc} @throws IllegalArgumentException {@inheritDoc}

findPred
Node!(E) findPred(Node!(E) p, Node!(E) ancestor)

Returns the predecessor of live node p, given a node that was once a live ancestor of p (or head); allows unlinking of p.

fullyLock
void fullyLock()

Locks to prevent both puts and takes.

fullyUnlock
void fullyUnlock()

Unlocks to allow both puts and takes.

offer
bool offer(E e, Duration timeout)

Inserts the specified element at the tail of this queue, waiting if necessary up to the specified wait time for space to become available.

offer
bool offer(E e)

Inserts the specified element at the tail of this queue if it is possible to do so immediately without exceeding the queue's capacity, returning {@code true} upon success and {@code false} if this queue is full. When using a capacity-restricted queue, this method is generally preferable to method {@link BlockingQueue#add add}, which can fail to insert an element only by throwing an exception.

opApply
int opApply(int delegate(ref E) dg)
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(IObject o)
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(Object o)
Undocumented in source. Be warned that the author may not have intended to support it.
peek
E peek()
Undocumented in source. Be warned that the author may not have intended to support it.
poll
E poll(Duration timeout)
Undocumented in source. Be warned that the author may not have intended to support it.
poll
E poll()
Undocumented in source. Be warned that the author may not have intended to support it.
put
void put(E e)

Inserts the specified element at the tail of this queue, waiting if necessary for space to become available.

remainingCapacity
int remainingCapacity()

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

remove
bool remove(E o)

Removes a single instance of the specified element from this queue, if it is present. More formally, removes an element {@code e} such that {@code o.equals(e)}, if this queue contains one or more such elements. Returns {@code true} if this queue contained the specified element (or equivalently, if this queue changed as a result of the call).

removeAll
bool removeAll(Collection!E c)

@throws NullPointerException {@inheritDoc}

removeIf
bool removeIf(Predicate!(E) filter)

@throws NullPointerException {@inheritDoc}

retainAll
bool retainAll(Collection!E c)

@throws NullPointerException {@inheritDoc}

size
int size()

Returns the number of elements in this queue.

succ
Node!(E) succ(Node!(E) p)

Used for any element traversal that is not entirely under lock. Such traversals must handle both: - dequeued nodes (p.next == p) - (possibly multiple) interior removed nodes (p.item is null)

take
E take()
Undocumented in source. Be warned that the author may not have intended to support it.
toArray
E[] toArray()

Returns an array containing all of the elements in this queue, in proper sequence.

toHash
size_t toHash()
Undocumented in source. Be warned that the author may not have intended to support it.
toString
string toString()

Returns an array containing all of the elements in this queue, in proper sequence; the runtime type of the returned array is that of the specified array. If the queue fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this queue.

Meta