Package com.github.jelmerk.knn.util
Class GenericObjectPool<T>
- java.lang.Object
-
- com.github.jelmerk.knn.util.GenericObjectPool<T>
-
- Type Parameters:
T
- type of object to pool
- All Implemented Interfaces:
Serializable
public class GenericObjectPool<T> extends Object implements Serializable
Generic object pool.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description GenericObjectPool(java.util.function.Supplier<T> supplier, int maxPoolSize)
Constructs a new pool
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
borrowObject()
Borrows an object from the pool.void
returnObject(T item)
Returns an instance to the pool.
-
-
-
Constructor Detail
-
GenericObjectPool
public GenericObjectPool(java.util.function.Supplier<T> supplier, int maxPoolSize)
Constructs a new pool- Parameters:
supplier
- used to create instances of the object to poolmaxPoolSize
- maximum items to have in the pool
-
-
Method Detail
-
borrowObject
public T borrowObject()
Borrows an object from the pool.- Returns:
- the borrowed object
-
returnObject
public void returnObject(T item)
Returns an instance to the pool. By contract, obj must have been obtained usingborrowObject()
- Parameters:
item
- the item to return to the pool
-
-