Package io.deephaven.util.datastructures
Class SegmentedSoftPool<ELEMENT_TYPE>
java.lang.Object
io.deephaven.util.datastructures.SegmentedSoftPool<ELEMENT_TYPE>
Re-usable data structure for a segmented stack of pooled elements which tries to strike a balance between GC-sensitivity and element reuse.
The pool is safe for multi-threaded use, but not highly-concurrent.
-
Constructor Summary
ConstructorDescriptionSegmentedSoftPool
(int segmentCapacity, @Nullable Supplier<ELEMENT_TYPE> creationProcedure, @Nullable Consumer<ELEMENT_TYPE> cleanupProcedure) Create a new pool with the supplied creation and cleanup procedures. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
give
(ELEMENT_TYPE element) Give an element to the pool.final ELEMENT_TYPE
take()
Take an element from the pool, or make a new one if the pool is exhausted and a creation procedure was supplied at pool construction time.
-
Constructor Details
-
SegmentedSoftPool
public SegmentedSoftPool(int segmentCapacity, @Nullable @Nullable Supplier<ELEMENT_TYPE> creationProcedure, @Nullable @Nullable Consumer<ELEMENT_TYPE> cleanupProcedure) Create a new pool with the supplied creation and cleanup procedures.- Parameters:
segmentCapacity
- The capacity of each segment of this pool. This is the unit of cleanup for the garbage collector.creationProcedure
- Creation procedure for new elements. If null, all elements must supplied viagive(java.lang.Object)
.cleanupProcedure
- Cleanup procedure for returned elements. If null, no cleanup will be performed ingive(java.lang.Object)
.
-
-
Method Details
-
take
Take an element from the pool, or make a new one if the pool is exhausted and a creation procedure was supplied at pool construction time. The element belongs to the caller, and the caller may keep it rather than return it to the pool if desired.- Returns:
- An element from the pool, possibly newly-constructed
-
give
Give an element to the pool. Neither the caller nor any other thread may interact with the element again until it has been returned by a subsequent call totake()
. The element will be cleaned if a cleanup procedure was provided at pool construction time.- Parameters:
element
- The element to give to the pool
-