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
Generic object pool.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionGenericObjectPool
(Supplier<T> supplier, int maxPoolSize) Constructs a new pool -
Method Summary
Modifier and TypeMethodDescriptionBorrows an object from the pool.void
returnObject
(T item) Returns an instance to the pool.
-
Constructor Details
-
GenericObjectPool
Constructs a new pool- Parameters:
supplier
- used to create instances of the object to poolmaxPoolSize
- maximum items to have in the pool
-
-
Method Details
-
borrowObject
Borrows an object from the pool.- Returns:
- the borrowed object
-
returnObject
Returns an instance to the pool. By contract, obj must have been obtained usingborrowObject()
- Parameters:
item
- the item to return to the pool
-