Supports two operations -- adding an element, and removing an element. The
LockFreePool#add(Object) operation adds an element into the pool. The
LockFreePool#get() operation returns one of the elements previously added to the pool.
There is no guarantee about the order in which the elements are returned by
LockFreePool#get(). The guarantee is that an element will only be returned by
LockFreePool#get() as many times as it was previously added to the pool by calling
LockFreePool#add(Object). If there are no more elements to return, it will return
null. Both operations are lock-free and linearizable -- this data structure is intended
for use by multiple threads.
The internal implementation is a simple Treiber stack.
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private final AtomicReference | head
The top-of-the-Treiber-stack pointer. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public T | Returns: A previously added element, ornull if there are no previously added elements
that have not been already returned.Returns a previously added element. |
| head | back to summary |
|---|---|
| private final AtomicReference<LockFreePool. The top-of-the-Treiber-stack pointer. | |
| LockFreePool | back to summary |
|---|---|
public LockFreePool()
| |
| add | back to summary |
|---|---|
| public void add(T element) Adds an element to this pool.
An element can be added multiple times to the pool, but in this case may be returned as many
times by
| |
| get | back to summary |
|---|---|
| public T get() Returns a previously added element.
This method returns a previously added element only once to some caller. If the element was
added multiple times, calling this method will return that element as many times before
returning
| |
tail pointer.
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final E | element
Element stored in this node. |
| pack-priv final LockFreePool. | tail
Pointer to the tail of the linked list, or |
| Access | Constructor and Description |
|---|---|
| private |
| element | back to summary |
|---|---|
| pack-priv final E element Element stored in this node. | |
| tail | back to summary |
|---|---|
| pack-priv final LockFreePool. Pointer to the tail of the linked list, or | |
| Node | back to summary |
|---|---|
| private Node(E element, LockFreePool. | |