public final class UtlPool<T extends UtlPool.Item<T>> extends Object
This class implements a pool used to recycle objects.
This class IS NOT intended to be used by end users.
Modifier and Type | Class and Description |
---|---|
static interface |
UtlPool.Factory<T extends UtlPool.Item<T>>
Defines the factory used by the pool to create new objects
|
static interface |
UtlPool.FlushedItemReceiver<T extends UtlPool.Item<T>>
Interface through which flushed items are dispatched to the user
|
static interface |
UtlPool.Item<T extends UtlPool.Item<T>>
Defines a 'poolable' item.
|
static class |
UtlPool.LockingStrategy
Enumerates the possible locking strategies for threaded pools.
|
static class |
UtlPool.Params
Specifies pool operating parameters.
|
class |
UtlPool.Stats
Stores pool statistics
|
Modifier and Type | Field and Description |
---|---|
static boolean |
POOL_LEAK_TYPE_TRACKING_ENABLED |
Modifier and Type | Method and Description |
---|---|
int |
capacity()
Return the current pool capacity
|
void |
close()
Close the pool
|
static <T extends UtlPool.Item<T>> |
create(String type,
String name,
UtlPool.Factory<T> factory,
UtlPool.Params params)
Create a new object pool.
|
static <T extends UtlPool.Item<T>> |
createPoolArray(int size)
Creates an empty
UtlPool array of the give size. |
void |
flush(UtlPool.FlushedItemReceiver<T> receiver)
Flush the pool
|
T |
get(Object object)
Get an item from an object pool.
|
static UtlPool.LockingStrategy |
getLockingStrategy()
Get whether lock free concurrency is enabled or not
|
boolean |
isClosed() |
static boolean |
isDetachedWashEnabled()
Get whether detached wash is enabled
|
static boolean |
isLockFreeConcurrencyEnabled()
Deprecated.
Use
getLockingStrategy() instead |
String |
key()
Get a pool's systemwide unique key
|
String |
name()
Get a pool's name
|
UtlPool.Params |
params()
Gets the creation
UtlPool.Params for the pool. |
void |
put(T item)
Release an item back into the pool
|
void |
setSingleThreaded()
Switch off threaded operation
|
int |
size()
Return the number of items in the pool
|
UtlPool.Stats |
stats()
Get the pool's statistics object
|
String |
type()
Get a pool's type
|
public static final boolean POOL_LEAK_TYPE_TRACKING_ENABLED
public static <T extends UtlPool.Item<T>> UtlPool<T> create(String type, String name, UtlPool.Factory<T> factory, UtlPool.Params params)
type
- The pool's typename
- The pool's unique name within its type. The pool's type
and name together serve as a pool's unique system-wide key.factory
- The factory to be used to create objects stored by
the pool being created.params
- Specifies pool operating parameters.public static final <T extends UtlPool.Item<T>> UtlPool<T>[] createPoolArray(int size)
UtlPool
array of the give size.size
- The size of the array.UtlPool
array of the give size.@Deprecated public static final boolean isLockFreeConcurrencyEnabled()
getLockingStrategy()
insteadpublic static final UtlPool.LockingStrategy getLockingStrategy()
public static final boolean isDetachedWashEnabled()
public final String type()
public final String name()
public final String key()
public final void setSingleThreaded()
public final T get(Object object)
object
- A user object passed to the item factory in case the
pool is empty and an item needs to be created fresh.public final void put(T item)
public final int size()
public final int capacity()
public final UtlPool.Stats stats()
public final UtlPool.Params params()
UtlPool.Params
for the pool.
When a pool is created its UtlPool.Params
are cloned and marked as read only.
This method allows the caller to determine the UtlPool.Params
with which the
pool was created.
UtlPool.Params
.public final void flush(UtlPool.FlushedItemReceiver<T> receiver)
receiver
- Receives the flushed items. This parameter can be null.
This method flushes all pool entries.
public final boolean isClosed()
public final void close()
Copyright © 2019 Neeve Research, LLC. All Rights Reserved.