E - type of elements kept in this pool.public class ThreadLocalPool<E> extends Object
LockFreePool.
This class is primarily designed for pooling of moderately-sized objects that may be needed so often,
as to raise concern about contention in LockFreePool implementation and memory locality concerns
on object reuse.
This class is a thread-safe.
| Modifier and Type | Field and Description |
|---|---|
static int |
MAX_THREAD_LOCAL_CAPACITY
Maximal supported thread local capacity.
|
| Constructor and Description |
|---|
ThreadLocalPool(int threadLocalCapacity,
int poolCapacity)
Creates a ThreadLocalPool with the specified (fixed) capacities.
|
ThreadLocalPool(String poolName,
int defaultThreadLocalCapacity,
int defaultPoolCapacity)
A convenience constructor that creates a ThreadLocalPool with a the specified default capacities,
which can be overriden by a JVM system properties.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
offer(E o)
Inserts the specified element into this pool.
|
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 that are available to the current thread.
|
public static final int MAX_THREAD_LOCAL_CAPACITY
public ThreadLocalPool(int threadLocalCapacity,
int poolCapacity)
ThreadLocalPool(poolName, defaultThreadLocalCapacity, defaultPoolCapacity)
that enables an override of pool's default capacities via JVM system properties if needed.threadLocalCapacity - the capacity of thread-local pool, e.g. how many objects are pooled per thread.poolCapacity - the capacity of the global LockFreePool, e.g. how many objects are pooled globally in addition to local ones.IllegalArgumentException - if thread local capacity is less than 1 or greater than MAX_THREAD_LOCAL_CAPACITY or
pool capacity is less than 1 or greater than LockFreePool.MAX_CAPACITY.public ThreadLocalPool(String poolName, int defaultThreadLocalCapacity, int defaultPoolCapacity)
poolName + ".threadLocalCapacity",
and for the global LockFreePool is poolName + ".poolCapacity".poolName - the base name of the pool.defaultThreadLocalCapacity - the default capacity of thread-local pool, e.g. how many objects are pooled per thread.defaultPoolCapacity - the default capacity of the global LockFreePool, e.g. how many objects are pooled globally in addition to local ones.IllegalArgumentException - if thread local capacity is less than 1 or greater than MAX_THREAD_LOCAL_CAPACITY or
pool capacity is less than 1 or greater than LockFreePool.MAX_CAPACITY.public int size()
public E poll()
public boolean offer(E o)
LockFreePool.o - the element to insert.true.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.