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 are weakly consistent, returning elements
reflecting the state of the deque at some point at or since the
creation of the iterator. They do not throw ConcurrentModificationException, and may proceed concurrently with
other operations.
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.
Additionally, the bulk operations addAll,
removeAll, retainAll, containsAll,
equals, and toArray are not guaranteed
to be performed atomically. For example, an iterator operating
concurrently with an addAll operation might view only some
of the added elements.
This class and its iterator implement all of the optional
methods of the java. and java. 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 | |
| private class | PortableConcurrentDirectDeque.
Descending iterator |
| private class | PortableConcurrentDirectDeque.
Forward iterator |
| pack-priv static class |
| Modifier and Type | Field and Description |
|---|---|
| private transient volatile PortableConcurrentDirectDeque. | 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 AtomicReferenceFieldUpdater | |
| private static final int | |
| private static final PortableConcurrentDirectDeque. | |
| private static final PortableConcurrentDirectDeque. | |
| private static final long | |
| private transient volatile PortableConcurrentDirectDeque. | 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 AtomicReferenceFieldUpdater |
| Access | Constructor and Description |
|---|---|
| public | |
| public | PortableConcurrentDirectDeque(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 | |
| 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 PortableConcurrentDirectDeque. | 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 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(PortableConcurrentDirectDeque.
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 PortableConcurrentDirectDeque. | 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 PortableConcurrentDirectDeque. | |
| private PortableConcurrentDirectDeque. | |
| pack-priv PortableConcurrentDirectDeque. | |
| 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 Object | offerFirstAndReturnToken(E e)
Implements abstract io.
|
| public boolean | offerLast(E
the element to add e)Implements java. Inserts the specified element at the end of this deque. |
| public Object | offerLastAndReturnToken(E e)
Implements abstract io.
|
| 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 PortableConcurrentDirectDeque. | pred(PortableConcurrentDirectDeque.
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 PortableConcurrentDirectDeque. | |
| 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 | |
| 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 element |
| 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 element |
| 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 element |
| public void | |
| 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 | |
| pack-priv final PortableConcurrentDirectDeque. | succ(PortableConcurrentDirectDeque.
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 ArrayList | |
| pack-priv void | |
| private void | unlinkFirst(PortableConcurrentDirectDeque.
Unlinks non-null first node. |
| private void | unlinkLast(PortableConcurrentDirectDeque.
Unlinks non-null last node. |
| private void | updateHead()
Guarantees that any node which was unlinked before a call to this method will be unreachable from head after it returns. |
| private 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 |