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:
  • Constructor Details

    • GenericObjectPool

      public GenericObjectPool(Supplier<T> supplier, int maxPoolSize)
      Constructs a new pool
      Parameters:
      supplier - used to create instances of the object to pool
      maxPoolSize - maximum items to have in the pool
  • Method Details

    • 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 using borrowObject()
      Parameters:
      item - the item to return to the pool