Class LocalPool<B>

java.lang.Object
org.cojen.tupl.util.LocalPool<B>

public final class LocalPool<B> extends Object
Utility for sharing a small set of poolable objects (like buffers) which have thread affinity. A thread should only request a single object from the pool to prevent deadlocks.
  • Constructor Details

    • LocalPool

      public LocalPool(Supplier<B> supplier)
      Construct a pool with a maximum size equal to the number of available processors.
      Parameters:
      supplier - can pass null to create entries which initially reference null
    • LocalPool

      public LocalPool(Supplier<B> supplier, int maxSize)
      Construct a pool with the given maximum size. If negative, then this is multiplied by the number of available processors and negated.
      Parameters:
      supplier - can pass null to create entries which initially reference null
  • Method Details

    • access

      public LocalPool.Entry<B> access()
      Returns an available pooled object, blocking if necessary.
    • clear

      public void clear(Consumer<B> consumer)
      Removes all pooled objects and passes them to the optional consumer for cleanup. Calling this method doesn't prevent new pooled objects from being created concurrently by the original supplier.