Class MCRPool<T>

java.lang.Object
org.mycore.util.concurrent.MCRPool<T>
Type Parameters:
T -

public class MCRPool<T> extends Object
A MCRPool allows thread safe pooling of thread unsafe objects.
  • Constructor Details

    • MCRPool

      public MCRPool(int size, Supplier<T> supplier)
      Creates an MCRPool of the given size
      Parameters:
      size - capacity of the pool
      supplier - return values for acquire(), called not more than size times
  • Method Details

    • acquire

      public T acquire() throws InterruptedException
      Acquires a value from the pool. The caller has to make sure that any instance returned is released afterwards.
      Throws:
      InterruptedException - if interrupted while waiting
    • release

      public void release(T resource)
      Puts the resource back into the pool.