Class PoolingSupport<T>

java.lang.Object
io.github.jbellis.jvector.util.PoolingSupport<T>
Type Parameters:
T - The object to be pooled by this instance

public abstract class PoolingSupport<T> extends Object
Allows any object to be pooled and released when work is done. This is an alternative to using ThreadLocal.
  • Method Details

    • newThreadBased

      public static <T> PoolingSupport<T> newThreadBased(Supplier<T> initialValue)
      Creates a pool of objects intended to be used by a thread pool. This is a replacement for ThreadLocal.
      Parameters:
      initialValue - allows creation of new instances for the pool
    • newNoPooling

      public static <T> PoolingSupport<T> newNoPooling(T fixedValue)
      Special case of not actually needing a pool (when other times you do)
      Parameters:
      fixedValue - the value this pool will always return
    • newQueuePooling

      public static <T> PoolingSupport<T> newQueuePooling(int limit, Supplier<T> initialValue)
      Recycling of objects using a MPMC queue
      Parameters:
      limit - the specific number of threads to be sharing the pooled objects
      initialValue - allows creation of new instances for the pool
    • get

      public abstract PoolingSupport.Pooled<T> get()
      Returns:
      a pooled object which will be returned to the pool when thread is finished with it
    • stream

      public abstract Stream<T> stream()
      This call returns all values what are in the pool, for the case of work spread across many pooled objects then processed after they are finished.
      Returns:
      a stream of everything in the pool.
      Throws:
      IllegalStateException - if outstanding items are not yet returned to the pool
    • onClosed

      protected abstract void onClosed(PoolingSupport.Pooled<T> value)
      Internal call used when pooled item is returned
      Parameters:
      value -