TransferQueue
based on linked nodes.
This queue orders elements FIFO (first-in-first-out) with respect
to any given producer. The head of the queue is that
element that has been on the queue the longest time for some
producer. The tail of the queue is that element that has
been on the queue the shortest time for some producer.
Beware that, unlike in most collections, the size
method
is NOT a constant-time operation. Because of the
asynchronous nature of these queues, determining the current number
of elements requires a traversal of the elements, and so may report
inaccurate results if this collection is modified during traversal.
Bulk operations that add, remove, or examine multiple elements,
such as addAll
, removeIf
or forEach
,
are not guaranteed to be performed atomically.
For example, a forEach
traversal concurrent with an addAll
operation might observe only some of the added elements.
This class and its iterator implement all of the optional
methods of the Collection
and Iterator
interfaces.
Memory consistency effects: As with other concurrent
collections, actions in a thread prior to placing an object into a
LinkedTransferQueue
happen-before
actions subsequent to the access or removal of that element from
the LinkedTransferQueue
in another thread.
This class is a member of the Java Collections Framework.
Modifier and Type | Class and Description |
---|---|
pack-priv static class | LinkedTransferQueue.
Node for linked dual data structures. |
pack-priv class | LinkedTransferQueue.
Weakly-consistent iterator. |
pack-priv class | LinkedTransferQueue.
A customized variant of Spliterators.IteratorSpliterator |
Modifier and Type | Field and Description |
---|---|
pack-priv transient volatile LinkedTransferQueue. | head
Unless empty (in which case possibly null), a node from which all live nodes are reachable. |
pack-priv static final VarHandle | |
private static final int | MAX_HOPS
Tolerate this many consecutive dead nodes before CAS-collapsing. |
private static final long | |
pack-priv static final int | SWEEP_THRESHOLD
The maximum number of estimated removal failures (sweepVotes) to tolerate before sweeping through the queue unlinking dead nodes that were initially pinned. |
pack-priv transient volatile int | sweepVotes
The number of apparent failures to unsplice cancelled nodes |
pack-priv static final VarHandle | |
pack-priv transient volatile LinkedTransferQueue. | tail
Unless null, a node from which the last node on list (that is, the unique node with node.next == null), if one exists, can be reached. |
pack-priv static final VarHandle |
Access | Constructor and Description |
---|---|
public | |
public | LinkedTransferQueue(Collection<? extends E>
the collection of elements to initially contain c)Creates a |
Modifier and Type | Method and Description |
---|---|
public boolean | add(E
the element to add e)Overrides java. Implements java. Inserts the specified element at the tail of this queue. |
private boolean | |
public void | clear()
Overrides java. Implements java. Removes all of the elements from this collection (optional operation). |
pack-priv final LinkedTransferQueue. | |
pack-priv final LinkedTransferQueue. | |
public boolean | Returns: true if this queue contains the specified elementobject to be checked for containment in this queue o)Overrides java. Implements java. Returns |
pack-priv final int | |
public int | drainTo(Collection<? super E>
the collection to transfer elements into c)Implements java. Removes all available elements from this queue and adds them to the given collection. |
public int | drainTo(Collection<? super E>
the collection to transfer elements into c, int the maximum number of elements to transfer maxElements)Implements java. Removes at most the given number of available elements from this queue and adds them to the given collection. |
pack-priv final LinkedTransferQueue. | |
public void | forEach(Consumer<? super E>
The action to be performed for each element action)Overrides default java. Performs the given action for each element of the |
pack-priv void | forEachFrom(Consumer<? super E> action, LinkedTransferQueue.
Runs action on each element found during a traversal starting at p. |
public int | getWaitingConsumerCount()
Implements java. Returns an estimate of the number of consumers waiting to
receive elements via |
public boolean | hasWaitingConsumer()
Implements java. Returns |
public boolean | Returns: true if this queue contains no elementsOverrides java. Implements java. Returns |
public Iterator | Returns: an iterator over the elements in this queue in proper sequenceImplements abstract java. Implements java. Returns an iterator over the elements in this queue in proper sequence. |
public boolean | offer(E
the element to add e, long how long to wait before giving up, in units of
timeout, TimeUnit unit a unit)TimeUnit determining how to interpret the
timeout parameterImplements java. Inserts the specified element at the tail of this queue. |
public boolean | offer(E
the element to add e)Implements java. Inserts the specified element at the tail of this queue. |
public E | peek()
Implements java. Retrieves, but does not remove, the head of this queue,
or returns |
public E | poll(long
how long to wait before giving up, in units of
timeout, TimeUnit unit a unit)TimeUnit determining how to interpret the
timeout parameterImplements java. Retrieves and removes the head of this queue, waiting up to the specified wait time if necessary for an element to become available. |
public E | poll()
Implements java. Retrieves and removes the head of this queue,
or returns |
public void | put(E
the element to add e)Implements java. Inserts the specified element at the tail of this queue. |
private void | readObject(ObjectInputStream
the stream s)Reconstitutes this queue from a stream (that is, deserializes it). |
public int | remainingCapacity()
Implements java. Always returns |
public boolean | Returns: true if this queue changed as a result of the callelement to be removed from this queue, if present o)Overrides java. Implements java. Removes a single instance of the specified element from this queue, if it is present. |
public boolean | removeAll(Collection<?>
collection containing elements to be removed from this collection c)Overrides java. Implements java. Removes all of this collection's elements that are also contained in the specified collection (optional operation). |
public boolean | removeIf(Predicate<? super E>
a predicate which returns filter)true for elements to be
removedOverrides default java. Removes all of the elements of this collection that satisfy the given predicate (optional operation). |
public boolean | retainAll(Collection<?>
collection containing elements to be retained in this collection c)Overrides java. Implements java. Retains only the elements in this collection that are contained in the specified collection (optional operation). |
public int | Returns: the number of elements in this queueImplements abstract java. Implements java. Returns the number of elements in this queue. |
pack-priv final LinkedTransferQueue. | Returns: pred if pred still alive and CAS succeeded; else pthe last known live node, or null if none pred,the first dead node c,the last dead node p,p.next: the next live node, or null if at end qCollapses dead (matched) nodes between pred and q. |
public Spliterator | Returns: aSpliterator over the elements in this queueOverrides default java. Returns a |
pack-priv final boolean | |
public E | take()
Implements java. Retrieves and removes the head of this queue, waiting if necessary until an element becomes available. |
public Object[] | Returns: an array containing all of the elements in this queueOverrides java. Implements java. Returns an array containing all of the elements in this queue, in proper sequence. |
public <T> T[] | Returns: an array containing all of the elements in this queuethe array into which the elements of the queue are to
be stored, if it is big enough; otherwise, a new array of the
same runtime type is allocated for this purpose a)Overrides java. Implements java. 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. |
private Object[] | |
public String | toString()
Overrides java. Returns a string representation of this collection. |
public void | transfer(E
the element to transfer e)Implements java. Transfers the element to a consumer, waiting if necessary to do so. |
pack-priv final boolean | tryCasSuccessor(LinkedTransferQueue.
Tries to CAS pred.next (or head, if pred is null) from c to p. |
pack-priv final boolean | tryMatchData(LinkedTransferQueue.
Tries to match the given object only if p is a data node. |
public boolean | tryTransfer(E
the element to transfer e)Implements java. Transfers the element to a waiting consumer immediately, if possible. |
public boolean | tryTransfer(E
the element to transfer e, long how long to wait before giving up, in units of
timeout, TimeUnit unit a unit)TimeUnit determining how to interpret the
timeout parameterImplements java. Transfers the element to a consumer if it is possible to do so before the timeout elapses. |
private void | unsplice(LinkedTransferQueue.
if nonnull, a node that was at one time known to be the
predecessor of s (else s may have been head) pred,the node to be unspliced sUnlinks (now or later) the given (non-live) node with given predecessor. |
private void | |
pack-priv final Object |