Class ThreadSafeFixedSizePool<T>

java.lang.Object
io.deephaven.util.pool.ThreadSafeFixedSizePool<T>
All Implemented Interfaces:
Pool<T>, PoolEx<T>

public class ThreadSafeFixedSizePool<T> extends Object implements PoolEx<T>
A pool that
  • holds at least size items,
  • creates size items in the pool immediately,
  • blocks (busily) whenever the pool overflows or underflows,
  • optionally clears the items given to it, and
  • IS thread-safe
  • Field Details

  • Constructor Details

    • ThreadSafeFixedSizePool

      public ThreadSafeFixedSizePool(int size, Supplier<T> factory, Consumer<T> clearingProcedure)
  • Method Details

    • give

      public void give(T item)
      Description copied from interface: Pool
      Gives an unused item back to the pool. Passing null is safe and has no effect. If the pool has a clearing procedure, the item will be cleared. Depending on pool policy, if the pool is full, this may block, discard the item, or throw a PoolFullException.
      Specified by:
      give in interface Pool<T>
    • take

      public T take()
      Description copied from interface: Pool
      Takes an item from the pool. Depending on pool policy, if there are no items available, this may block, create a new item, or throw a PoolEmptyException.
      Specified by:
      take in interface Pool<T>
    • tryTake

      public T tryTake()
      Description copied from interface: PoolEx
      Take an item if immediately available, else return null.
      Specified by:
      tryTake in interface PoolEx<T>
      Returns:
      a pool item or null