DATATYPE - The type of the objects contained in the pool.@ThreadSafe public final class ObjectPool<DATATYPE> extends Object implements IMutableObjectPool<DATATYPE>
| Constructor and Description |
|---|
ObjectPool(int nItemCount,
ISupplier<? extends DATATYPE> aFactory)
Create a new object pool for a certain amount of items and a factory that
creates the objects on demand.
|
| Modifier and Type | Method and Description |
|---|---|
DATATYPE |
borrowObject()
Borrow an object from the pool.
|
void |
clearUnusedItems() |
static boolean |
isSilentMode() |
ESuccess |
returnObject(DATATYPE aItem)
Return a previously borrowed object back to the pool.
|
static boolean |
setSilentMode(boolean bSilentMode)
Enable or disable certain regular log messages.
|
public ObjectPool(@Nonnegative int nItemCount, @Nonnull ISupplier<? extends DATATYPE> aFactory)
nItemCount - The number of items in the pool. Must be ≥ 1.aFactory - The factory to create object. May not be null. The
factory may not create null objects, as this leads to
an error!public static boolean isSilentMode()
true if logging is disabled, false if it
is enabled.public static boolean setSilentMode(boolean bSilentMode)
bSilentMode - true to disable logging, false to enable
loggingpublic void clearUnusedItems()
@Nullable public DATATYPE borrowObject()
IMutableObjectPoolborrowObject in interface IMutableObjectPool<DATATYPE>null depending on the
factory, and the locking used.@Nonnull public ESuccess returnObject(@Nonnull DATATYPE aItem)
IMutableObjectPoolreturnObject in interface IMutableObjectPool<DATATYPE>aItem - The previously borrowed object to be returned. Never
null.ESuccess.SUCCESS upon successCopyright © 2014–2020 Philip Helger. All rights reserved.