DATATYPE
- The type of the objects contained in the pool.@ThreadSafe public final class ObjectPool<DATATYPE> extends Object implements IObjectPool<DATATYPE>
Constructor and Description |
---|
ObjectPool(int nItemCount,
IFactory<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.
|
ESuccess |
returnObject(DATATYPE aItem)
Return a previously borrowed object back to the pool.
|
public ObjectPool(@Nonnegative int nItemCount, @Nonnull IFactory<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!@Nullable public DATATYPE borrowObject()
IObjectPool
borrowObject
in interface IObjectPool<DATATYPE>
null
depending on the
factory, and the locking used.@Nonnull public ESuccess returnObject(@Nonnull DATATYPE aItem)
IObjectPool
returnObject
in interface IObjectPool<DATATYPE>
aItem
- The previously borrowed object to be returned. Never
null
.ESuccess.SUCCESS
upon successCopyright © 2014–2015 Philip Helger. All rights reserved.