E - element type in the queue.public class ManyToOneConcurrentLinkedQueue<E> extends Object implements Queue<E>
Queue that can be used from many producers and a single consumer.
This is a Java port of Dmitry Vyukov's MPSC linked queue.
Note: This queue breaks the contract for peek and poll in that it can return null when the queue has no item available but size could be greater than zero if an offer is in progress. This is due to the offer being a multi-step process which can start and be interrupted before completion, the thread will later be resumed and the offer process completes. Other methods, such as peek and poll, could spin internally waiting on the offer to complete to provide sequentially consistency across methods but this can have a detrimental effect in a resource starved system. This internal spinning eats up a CPU core and prevents other threads making progress resulting in latency spikes. To avoid this a more relaxed approach is taken in that an in-progress offer is not waited on to complete.
If you wish to check for empty then call isEmpty() rather than size() checking for zero.
| Modifier and Type | Field and Description |
|---|---|
protected org.agrona.concurrent.ManyToOneConcurrentLinkedQueuePadding1.Node<E> |
head |
protected static long |
HEAD_OFFSET |
protected static long |
NEXT_OFFSET |
protected org.agrona.concurrent.ManyToOneConcurrentLinkedQueuePadding1.Node<E> |
tail |
protected static long |
TAIL_OFFSET |
| Constructor and Description |
|---|
ManyToOneConcurrentLinkedQueue() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E e) |
boolean |
addAll(Collection<? extends E> c) |
void |
clear() |
boolean |
contains(Object o) |
boolean |
containsAll(Collection<?> c) |
E |
element() |
boolean |
isEmpty() |
Iterator<E> |
iterator() |
boolean |
offer(E e) |
E |
peek() |
E |
poll() |
E |
remove() |
boolean |
remove(Object o) |
boolean |
removeAll(Collection<?> c) |
boolean |
retainAll(Collection<?> c) |
int |
size()
Size can be considered an approximation on a moving list.
|
Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitequals, hashCode, parallelStream, removeIf, spliterator, streamprotected volatile org.agrona.concurrent.ManyToOneConcurrentLinkedQueuePadding1.Node<E> head
protected volatile org.agrona.concurrent.ManyToOneConcurrentLinkedQueuePadding1.Node<E> tail
protected static final long HEAD_OFFSET
protected static final long TAIL_OFFSET
protected static final long NEXT_OFFSET
public boolean add(E e)
public int size()
queue.size() == 0 then isEmpty() is a better alternative.
This operation is O(n) on the length of the linked chain.
size in interface Collection<E>public boolean isEmpty()
isEmpty in interface Collection<E>public boolean contains(Object o)
contains in interface Collection<E>public Object[] toArray()
toArray in interface Collection<E>public <T> T[] toArray(T[] a)
toArray in interface Collection<E>public boolean remove(Object o)
remove in interface Collection<E>public boolean containsAll(Collection<?> c)
containsAll in interface Collection<E>public boolean addAll(Collection<? extends E> c)
addAll in interface Collection<E>public boolean removeAll(Collection<?> c)
removeAll in interface Collection<E>public boolean retainAll(Collection<?> c)
retainAll in interface Collection<E>public void clear()
clear in interface Collection<E>Copyright © 2014-2020 Real Logic Limited. All Rights Reserved.