E
- type of elements kept in this pool.public class LockFreePool<E> extends Object
The LockFreePool is a fixed-capacity (or "bounded") stack as it orders elements in a LIFO (last-in-first-out) manner. This class is a thread-safe and provides lock-free access.
If you need a pool of moderately-sized objects that may be needed so often, as to raise concern about
contention on this LockFreePool
implementation and memory locality concerns on object reuse,
then use ThreadLocalPool
class and keeps an additional per-thread pool of objects.
Modifier and Type | Field and Description |
---|---|
static int |
MAX_CAPACITY
Maximal supported pool capacity.
|
Constructor and Description |
---|
LockFreePool(int poolCapacity)
Creates a LockFreePool with the specified (fixed) capacity.
|
LockFreePool(String poolName,
int defaultPoolCapacity)
A convenience constructor that creates a LockFreePool with a the specified default capacity,
which can be overriden by a JVM system property.
|
Modifier and Type | Method and Description |
---|---|
boolean |
offer(E o)
Inserts the specified element into this pool, if possible.
|
E |
poll()
Retrieves and removes the element from this pool, or null if this pool is empty.
|
int |
size()
Returns the number of elements in this pool.
|
public static final int MAX_CAPACITY
public LockFreePool(int poolCapacity)
LockFreePool(poolName, defaultCapacity)
that enables an override of
pool's default capacity via JVM system property if needed.poolCapacity
- the capacity of this pool.IllegalArgumentException
- if pool capacity is less than 1 or greater than MAX_CAPACITY
.public LockFreePool(String poolName, int defaultPoolCapacity)
poolName + ".poolCapacity"
.poolName
- the base name of the pool.defaultPoolCapacity
- the default capacity of this pool.IllegalArgumentException
- if pool capacity is less than 1 or greater than MAX_CAPACITY
.public int size()
public E poll()
public boolean offer(E o)
o
- the element to insert.NullPointerException
- if element is null.IllegalStateException
- if element is already in the pool (best effort check only).Copyright © 2002–2025 Devexperts LLC. All rights reserved.