Package io.github.jbellis.jvector.util
Class PoolingSupport<T>
java.lang.Object
io.github.jbellis.jvector.util.PoolingSupport<T>
- Type Parameters:
T- The object to be pooled by this instance
Allows any object to be pooled and released when work is done.
This is an alternative to using
ThreadLocal.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classWrapper 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 TypeMethodDescriptionabstract PoolingSupport.Pooled<T>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 poolstatic <T> PoolingSupport<T>newThreadBased(Supplier<T> initialValue) Creates a pool of objects intended to be used by a fixed thread pool.protected abstract voidInternal call used when pooled item is returnedstream()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.
-
Method Details
-
newThreadBased
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
Creates a pool intended to be used by a fixed thread pool- Parameters:
threadLimit- the specific number of threads to be sharing the pooled objectsinitialValue- allows creation of new instances for the pool
-
newNoPooling
Special case of not actually needing a pool (when other times you do)- Parameters:
fixedValue- the value this pool will always return
-
get
- Returns:
- a pooled object which will be returned to the pool when thread is finished with it
-
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
Internal call used when pooled item is returned- Parameters:
value-
-