Class ThreadSafeFixedSizePool<T>

java.lang.Object
com.illumon.util.pool.ThreadSafeFixedSizePool<T>
All Implemented Interfaces:
com.fishlib.base.pool.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
Forked from com.fishlib.base.pool.ThreadSafeLenientFixedSizePool January 2021
  • Nested Class Summary

    Nested classes/interfaces inherited from interface com.fishlib.base.pool.Pool

    com.fishlib.base.pool.Pool.Factory, com.fishlib.base.pool.Pool.MultiGiver<T extends Object>, com.fishlib.base.pool.Pool.MultiPool<T extends Object>, com.fishlib.base.pool.Pool.MultiTaker<T extends Object>, com.fishlib.base.pool.Pool.SinglePool<T extends Object>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    protected final LockFreeArrayQueue<T>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    ThreadSafeFixedSizePool(int size, com.fishlib.base.Function.Nullary<T> factory, com.fishlib.base.Procedure.Unary<T> clearingProcedure)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    give(T item)
     
     
    Take an item if immediately available, else return null.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • ThreadSafeFixedSizePool

      public ThreadSafeFixedSizePool(int size, com.fishlib.base.Function.Nullary<T> factory, com.fishlib.base.Procedure.Unary<T> clearingProcedure)
  • Method Details

    • give

      public void give(T item)
      Specified by:
      give in interface com.fishlib.base.pool.Pool<T>
    • take

      public T take()
      Specified by:
      take in interface com.fishlib.base.pool.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