E
- @SuppressAnimalSniffer public final class SpscArrayQueue<E> extends ConcurrentCircularArrayQueue<E>
This implementation is a mashup of the Fast Flow
algorithm with an optimization of the offer method taken from the BQueue algorithm (a variation on Fast
Flow), and adjusted to comply with Queue.offer semantics with regards to capacity.
For convenience the relevant papers are available in the resources folder:
2010 - Pisa - SPSC Queues on Shared Cache Multi-Core Systems.pdf
2012 - Junchang- BQueue- Efficient and Practical Queuing.pdf
This implementation is wait free.
Modifier and Type | Field and Description |
---|---|
protected static long |
C_INDEX_OFFSET |
protected long |
consumerIndex |
protected int |
lookAheadStep |
protected static long |
P_INDEX_OFFSET |
protected long |
producerIndex |
protected long |
producerLookAhead |
buffer, BUFFER_PAD, mask, SPARSE_SHIFT
Constructor and Description |
---|
SpscArrayQueue(int capacity) |
Modifier and Type | Method and Description |
---|---|
boolean |
isEmpty()
This method's accuracy is subject to concurrent modifications happening as the observation is carried out.
|
boolean |
offer(E e)
Called from a producer thread subject to the restrictions appropriate to the implementation and according to the
Queue.offer(Object) interface. |
E |
peek()
Called from the consumer thread subject to the restrictions appropriate to the implementation and according to
the
Queue.peek() interface. |
E |
poll()
Called from the consumer thread subject to the restrictions appropriate to the implementation and according to
the
Queue.poll() interface. |
int |
size()
This method's accuracy is subject to concurrent modifications happening as the size is estimated and as such is a
best effort rather than absolute value.
|
calcElementOffset, calcElementOffset, clear, iterator, lpElement, lpElement, lvElement, lvElement, soElement, soElement, spElement, spElement
add, addAll, element, remove
contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
contains, containsAll, equals, hashCode, parallelStream, remove, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray
protected long consumerIndex
protected static final long C_INDEX_OFFSET
protected static final long P_INDEX_OFFSET
protected long producerIndex
protected long producerLookAhead
protected final int lookAheadStep
public boolean offer(E e)
Queue.offer(Object)
interface.
This implementation is correct for single producer thread use only.
e
- the Object to enqueue, not nullpublic E poll()
Queue.poll()
interface.
This implementation is correct for single consumer thread use only.
public E peek()
Queue.peek()
interface.
This implementation is correct for single consumer thread use only.
public int size()
MessagePassingQueue
size
in interface Collection<E>
size
in interface MessagePassingQueue<E>
size
in class AbstractCollection<E>
Integer.MAX_VALUE
if not boundedpublic boolean isEmpty()
MessagePassingQueue
isEmpty
in interface Collection<E>
isEmpty
in interface MessagePassingQueue<E>
isEmpty
in class AbstractCollection<E>
Copyright © 2018. All rights reserved.