Class PushPullConcurrentQueue<E>
java.lang.Object
com.conversantmedia.util.concurrent.PushPullConcurrentQueue<E>
- All Implemented Interfaces:
ConcurrentQueue<E>
- Direct Known Subclasses:
PushPullBlockingQueue
Tuned version of Martin Thompson's push pull queue
Transfers from a single thread writer to a single thread reader are orders of nanoseconds (3-5)
This code is optimized and tested using a 64bit HotSpot JVM on an Intel x86-64 environment. Other
environments should be carefully tested before using in production.
Created by jcairns on 5/28/14.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintcapacity()voidclear()clear the queue of all elementsfinal booleanfinal booleanisEmpty()booleanAdd element t to the ringfinal Epeek()return the first element in the queuepoll()remove the first element from the queue and return itintreturn all elements in the queue to the provided array, up to the size of the provided array.final intsize()This implemention is known to be broken if preemption were to occur after reading the tail pointer.
-
Constructor Details
-
PushPullConcurrentQueue
public PushPullConcurrentQueue(int capacity)
-
-
Method Details
-
offer
Description copied from interface:ConcurrentQueueAdd element t to the ring- Specified by:
offerin interfaceConcurrentQueue<E>- Parameters:
e- - element to offer- Returns:
- boolean - true if the operation succeeded
-
poll
Description copied from interface:ConcurrentQueueremove the first element from the queue and return it- Specified by:
pollin interfaceConcurrentQueue<E>- Returns:
- T
-
remove
Description copied from interface:ConcurrentQueuereturn all elements in the queue to the provided array, up to the size of the provided array.- Specified by:
removein interfaceConcurrentQueue<E>- Parameters:
e- - The element array- Returns:
- int - the number of elements added to t
-
clear
public void clear()Description copied from interface:ConcurrentQueueclear the queue of all elements- Specified by:
clearin interfaceConcurrentQueue<E>
-
peek
Description copied from interface:ConcurrentQueuereturn the first element in the queue- Specified by:
peekin interfaceConcurrentQueue<E>- Returns:
- E - The element
-
size
public final int size()This implemention is known to be broken if preemption were to occur after reading the tail pointer. Code should not depend on size for a correct result.- Specified by:
sizein interfaceConcurrentQueue<E>- Returns:
- int - possibly the size, or possibly any value less than capacity()
-
capacity
public int capacity()- Specified by:
capacityin interfaceConcurrentQueue<E>- Returns:
- int - the capacity of the queue
-
isEmpty
public final boolean isEmpty()- Specified by:
isEmptyin interfaceConcurrentQueue<E>- Returns:
- boolean - true if the queue is currently empty
-
contains
- Specified by:
containsin interfaceConcurrentQueue<E>- Parameters:
o- - the object to test- Returns:
- boolean - true if specified object is contained in the queue
-