Class Pool<T>

java.lang.Object
org.sejda.commons.Pool<T>

public class Pool<T> extends Object
A simple object pool implementation. It requires a Supplier used to create instances to pool and when an object is requested but the pool is exhausted.
Author:
Andrea Vacondio
  • Constructor Details

    • Pool

      public Pool(Supplier<T> creator, int poolsize)
  • Method Details

    • borrow

      public T borrow()
      Returns:
      the instance borrowed from the pool
    • give

      public void give(T object)
      Returns the object to the pool
      Parameters:
      object -
    • onGive

      public Pool<T> onGive(Consumer<T> applyOnGive)
      Configure the pool to apply the given consumer to returned objects. This might be useful to restore initial status on returned objects.
      Parameters:
      applyOnGive -
      Returns:
      the pool