edu.emory.mathcs.backport.java.util.concurrent
public class ConcurrentLinkedQueue extends AbstractQueue implements Queue, Serializable
This implementation employs an efficient "wait-free" algorithm based on one described in Simple, Fast, and Practical Non-Blocking and Blocking Concurrent Queue Algorithms by Maged M. Michael and Michael L. Scott.
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.
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 {@code ConcurrentLinkedQueue} happen-before actions subsequent to the access or removal of that element from the {@code ConcurrentLinkedQueue} in another thread.
This class is a member of the Java Collections Framework.
Since: 1.5
Constructor Summary | |
---|---|
ConcurrentLinkedQueue()
Creates a ConcurrentLinkedQueue that is initially empty. | |
ConcurrentLinkedQueue(Collection c)
Creates a ConcurrentLinkedQueue
initially containing the elements of the given collection,
added in traversal order of the collection's iterator. |
Method Summary | |
---|---|
boolean | add(Object e)
Inserts the specified element at the tail of this queue.
|
boolean | contains(Object o)
Returns true if this queue contains the specified element.
|
boolean | isEmpty()
Returns true if this queue contains no elements.
|
Iterator | iterator()
Returns an iterator over the elements in this queue in proper sequence.
|
boolean | offer(Object e)
Inserts the specified element at the tail of this queue.
|
Object | peek() |
Object | poll() |
boolean | remove(Object o)
Removes a single instance of the specified element from this queue,
if it is present. |
int | size()
Returns the number of elements in this queue. |
Parameters: c the collection of elements to initially contain
Throws: NullPointerException if the specified collection or any of its elements are null
Returns: true (as specified by Collection#add)
Throws: NullPointerException if the specified element is null
Parameters: o object to be checked for containment in this queue
Returns: true if this queue contains the specified element
Returns: true if this queue contains no elements
Returns: an iterator over the elements in this queue in proper sequence
Returns: true (as specified by Queue)
Throws: NullPointerException if the specified element is null
Parameters: o element to be removed from this queue, if present
Returns: true if this queue changed as a result of the call
Beware that, unlike in most collections, this method is NOT a constant-time operation. Because of the asynchronous nature of these queues, determining the current number of elements requires an O(n) traversal.
Returns: the number of elements in this queue