T
- the contained value typepublic final class SpscLinkedArrayQueue<T> extends Object implements SimplePlainQueue<T>
Constructor and Description |
---|
SpscLinkedArrayQueue(int bufferSize) |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all enqueued items from this queue.
|
boolean |
isEmpty()
Returns true if the queue is empty.
|
boolean |
offer(T e)
Atomically enqueue a single.
|
boolean |
offer(T first,
T second)
Offer two elements at the same time.
|
T |
peek() |
T |
poll()
Tries to dequeue a value (non-null) or returns null if
the queue is empty.
|
int |
size() |
public boolean offer(T e)
This implementation is correct for single producer thread use only.
offer
in interface SimpleQueue<T>
e
- the value to enqueue, not null@Nullable public T poll()
If the producer uses SimpleQueue.offer(Object, Object)
and
when polling in pairs, if the first poll() returns a non-null
item, the second poll() is guaranteed to return a non-null item
as well.
This implementation is correct for single consumer thread use only.
poll
in interface SimplePlainQueue<T>
poll
in interface SimpleQueue<T>
public T peek()
public void clear()
SimpleQueue
clear
in interface SimpleQueue<T>
public int size()
public boolean isEmpty()
SimpleQueue
Note however that due to potential fused functions in SimpleQueue.poll()
it is possible this method returns false but then poll() returns null
because the fused function swallowed the available item(s).
isEmpty
in interface SimpleQueue<T>
public boolean offer(T first, T second)
Don't use the regular offer() with this at all!
offer
in interface SimpleQueue<T>
first
- the first value, not nullsecond
- the second value, not nullCopyright © 2019. All rights reserved.