E
- element type.public class SimpleConcurrentQueue<E> extends Object
Simple concurrent lock-free queue backed by a linked list.
Internally, this queue uses a very simple one-directional linked list that is updated using atomic operations. This way, the queue is both thread safe and lock free.
The add(Object)
, peek()
, and removeIfMatch(Object)
operations are O(1). However, due to the concurrent nature of this
implementation, internal operations might fail occasionally and are repeated
until they succeed. Therefore, the time needed for a specific operation is
non-deterministic.
Constructor and Description |
---|
SimpleConcurrentQueue()
Creates an empty queue.
|
Modifier and Type | Method and Description |
---|---|
void |
add(E e)
Adds an element to the tail of the queue.
|
E |
peek()
Returns the element at the head of the queue without removing it.
|
boolean |
removeIfMatch(E expect)
Removes the head of the queue if it matches the specified element.
|
public void add(E e)
e
- element to be added. Must not be null
.public boolean removeIfMatch(E expect)
expect
- element expected at the head of the queue.true
if the expected element was at the head of the
queue and has been removed, false
if the head of the
queue did not match the expected element and thus was not
removed.public E peek()
null
if the
queue is empty.Copyright © 2014–2016 aquenos GmbH. All rights reserved.