ConcurrentLinkedDeque
is an appropriate choice when
many threads will share access to a common collection.
Like most other concurrent collection implementations, this class
does not permit the use of null
elements.
Iterators and spliterators are weakly consistent.
Beware that, unlike in most collections, the size
method
is NOT a constant-time operation. Because of the
asynchronous nature of these deques, 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 Deque
and Iterator
interfaces.
Memory consistency effects: As with other concurrent collections,
actions in a thread prior to placing an object into a
ConcurrentLinkedDeque
happen-before
actions subsequent to the access or removal of that element from
the ConcurrentLinkedDeque
in another thread.
This class is a member of the Java Collections Framework.
Modifier and Type | Class and Description |
---|---|
private abstract class | |
pack-priv class | ConcurrentLinkedDeque.
A customized variant of Spliterators.IteratorSpliterator |
private class | ConcurrentLinkedDeque.
Descending iterator |
private class | ConcurrentLinkedDeque.
Forward iterator |
pack-priv static class |
Modifier and Type | Field and Description |
---|---|
private transient volatile ConcurrentLinkedDeque. | head
A node from which the first node on list (that is, the unique node p with p.prev == null && p.next != p) can be reached in O(1) time. |
private static final VarHandle | |
private static final int | |
private static final VarHandle | |
private static final VarHandle | |
private static final ConcurrentLinkedDeque. | |
private static final VarHandle | |
private static final ConcurrentLinkedDeque. | |
private static final long | |
private transient volatile ConcurrentLinkedDeque. | tail
A node from which the last node on list (that is, the unique node p with p.next == null && p.prev != p) can be reached in O(1) time. |
private static final VarHandle |
Access | Constructor and Description |
---|---|
public | |
public | ConcurrentLinkedDeque(Collection<? extends E>
the collection of elements to initially contain c)Constructs a deque initially containing the elements of the given collection, added in traversal order of the collection's iterator. |
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 deque. |
public boolean | Returns: true if this deque changed as a result of the callthe elements to be inserted into this deque c)Overrides java. Implements java. Appends all of the elements in the specified collection to the end of this deque, in the order that they are returned by the specified collection's iterator. |
public void | addFirst(E
the element to add e)Implements java. Inserts the specified element at the front of this deque. |
public void | addLast(E
the element to add e)Implements java. Inserts the specified element at the end of this deque. |
private boolean | |
public void | clear()
Overrides java. Implements java. Removes all of the elements from this deque. |
public boolean | Returns: true if this deque contains the specified elementelement whose presence in this deque is to be tested o)Overrides java. Implements java. Returns |
public Iterator | Returns: an iterator over the elements in this deque in reverse orderImplements java. Returns an iterator over the elements in this deque in reverse sequential order. |
public E | element()
Implements java. Retrieves, but does not remove, the head of the queue represented by this deque (in other words, the first element of this deque). |
pack-priv ConcurrentLinkedDeque. | first()
Returns the first node, the unique node p for which: p.prev == null && p.next != p The returned node may or may not be logically deleted. |
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 |
public E | getFirst()
Implements java. Retrieves, but does not remove, the first element of this deque. |
public E | getLast()
Implements java. Retrieves, but does not remove, the last element of this deque. |
private void | initHeadTail(ConcurrentLinkedDeque.
Initializes head and tail, ensuring invariants hold. |
public boolean | Returns: true if this collection contains no elementsOverrides java. Implements java. Returns |
public Iterator | Returns: an iterator over the elements in this deque in proper sequenceImplements abstract java. Implements java. Returns an iterator over the elements in this deque in proper sequence. |
pack-priv ConcurrentLinkedDeque. | last()
Returns the last node, the unique node p for which: p.next == null && p.prev != p The returned node may or may not be logically deleted. |
private void | |
private void | |
pack-priv static <E> ConcurrentLinkedDeque. | |
pack-priv ConcurrentLinkedDeque. | |
public boolean | offer(E
the element to add e)Implements java. Inserts the specified element at the tail of this deque. |
public boolean | offerFirst(E
the element to add e)Implements java. Inserts the specified element at the front of this deque. |
public boolean | offerLast(E
the element to add e)Implements java. Inserts the specified element at the end of this deque. |
public E | peek()
Implements java. Retrieves, but does not remove, the head of the queue represented by
this deque (in other words, the first element of this deque), or
returns |
public E | peekFirst()
Implements java. Retrieves, but does not remove, the first element of this deque,
or returns |
public E | peekLast()
Implements java. Retrieves, but does not remove, the last element of this deque,
or returns |
public E | poll()
Implements java. Retrieves and removes the head of the queue represented by this deque
(in other words, the first element of this deque), or returns
|
public E | pollFirst()
Implements java. Retrieves and removes the first element of this deque,
or returns |
public E | pollLast()
Implements java. Retrieves and removes the last element of this deque,
or returns |
public E | |
pack-priv final ConcurrentLinkedDeque. | pred(ConcurrentLinkedDeque.
Returns the predecessor of p, or the last node if p.prev has been linked to self, which will only be true if traversing with a stale pointer that is now off the list. |
pack-priv ConcurrentLinkedDeque. | |
public void | push(E
the element to push e)Implements java. Pushes an element onto the stack represented by this deque (in other
words, at the head of this deque) if it is possible to do so
immediately without violating capacity restrictions, throwing an
|
private void | readObject(ObjectInputStream
the stream s)Reconstitutes this deque from a stream (that is, deserializes it). |
public E | remove()
Implements java. Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque). |
public boolean | Returns: true if the deque contained the specified elementelement to be removed from this deque, if present o)Overrides java. Implements java. Removes the first occurrence of the specified element from this deque. |
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 E | removeFirst()
Implements java. Retrieves and removes the first element of this deque. |
public boolean | Returns: true if the deque contained the specified elementelement to be removed from this deque, if present o)Implements java. Removes the first occurrence of the specified element from this deque. |
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 E | removeLast()
Implements java. Retrieves and removes the last element of this deque. |
public boolean | Returns: true if the deque contained the specified elementelement to be removed from this deque, if present o)Implements java. Removes the last occurrence of the specified element from this deque. |
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). |
private E | Returns: the elementthe element v)Returns element unless it is null, in which case throws NoSuchElementException. |
public int | Returns: the number of elements in this dequeImplements abstract java. Implements java. Returns the number of elements in this deque. |
private void | |
private void | |
public Spliterator | Returns: aSpliterator over the elements in this dequeOverrides default java. Returns a |
pack-priv final ConcurrentLinkedDeque. | succ(ConcurrentLinkedDeque.
Returns the successor of p, or the first node if p.next has been linked to self, which will only be true if traversing with a stale pointer that is now off the list. |
public Object[] | Returns: an array containing all of the elements in this dequeOverrides java. Implements java. Returns an array containing all of the elements in this deque, in proper sequence (from first to last element). |
public <T> T[] | Returns: an array containing all of the elements in this dequethe array into which the elements of the deque 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 deque, in proper sequence (from first to last element); 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. |
pack-priv void | |
private void | unlinkFirst(ConcurrentLinkedDeque.
Unlinks non-null first node. |
private void | unlinkLast(ConcurrentLinkedDeque.
Unlinks non-null last node. |
private final void | updateHead()
Guarantees that any node which was unlinked before a call to this method will be unreachable from head after it returns. |
private final void | updateTail()
Guarantees that any node which was unlinked before a call to this method will be unreachable from tail after it returns. |
private void |