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.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Wrapper class for items in the pool These are AutoClosable and are intended to be used in a try-with-resources statement.
  • Method Summary

    Modifier and Type
    Method
    Description
    get()
     
    static <T> PoolingSupport<T>
    newNoPooling(T fixedValue)
    Special case of not actually needing a pool (when other times you do)
    static <T> PoolingSupport<T>
    newThreadBased(int threadLimit, Supplier<T> initialValue)
    Creates a pool intended to be used by a fixed thread pool
    static <T> PoolingSupport<T>
    newThreadBased(Supplier<T> initialValue)
    Creates a pool of objects intended to be used by a fixed thread pool.
    protected abstract void
    onClosed(T value)
    Internal call used when pooled item is returned
    abstract Stream<T>
    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.

    Methods inherited from class java.lang.Object

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

    • newThreadBased

      public static <T> PoolingSupport<T> newThreadBased(Supplier<T> initialValue)
      Creates a pool of objects intended to be used by a fixed thread pool. The pool size will the processor count.
      Parameters:
      initialValue - allows creation of new instances for the pool
    • newThreadBased

      public static <T> PoolingSupport<T> newThreadBased(int threadLimit, Supplier<T> initialValue)
      Creates a pool intended to be used by a fixed thread pool
      Parameters:
      threadLimit - the specific number of threads to be sharing the pooled objects
      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
    • 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(T value)
      Internal call used when pooled item is returned
      Parameters:
      value -