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() |
ESuccess |
returnObject(DATATYPE aItem)
Return a previously borrowed object back to the pool.
|
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 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–2019 Philip Helger. All rights reserved.