Class SegmentedSoftPool<ELEMENT_TYPE>

java.lang.Object
io.deephaven.util.datastructures.SegmentedSoftPool<ELEMENT_TYPE>

public class SegmentedSoftPool<ELEMENT_TYPE> extends Object

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 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 via give(java.lang.Object).
      cleanupProcedure - Cleanup procedure for returned elements. If null, no cleanup will be performed in give(java.lang.Object).
  • Method Details

    • take

      public 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. 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

      public final void give(@NotNull ELEMENT_TYPE element)
      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 to take(). The element will be cleaned if a cleanup procedure was provided at pool construction time.
      Parameters:
      element - The element to give to the pool