T- Type of the elements in this pool.
public class LockFreePool<T> extends Object
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.
|Constructor and Description|
|Modifier and Type||Method and Description|
Adds an element to this pool.
Returns a previously added element.
public T get()
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
This method does not do any object allocations.
nullif there are no previously added elements that have not been already returned.
public void add(T element)
An element can be added multiple times to the pool, but in this case may be returned as many
This method internally allocates objects on the heap.
element- An element to add to the pool.