Interface RecyclerPool<P extends RecyclerPool.WithPool<P>>

Type Parameters:
P - Type of Objects pool recycles
All Superinterfaces:
Serializable
All Known Implementing Classes:
JsonRecyclerPools.BoundedPool, JsonRecyclerPools.ConcurrentDequePool, JsonRecyclerPools.LockFreePool, JsonRecyclerPools.NonRecyclingPool, JsonRecyclerPools.ThreadLocalPool, RecyclerPool.BoundedPoolBase, RecyclerPool.ConcurrentDequePoolBase, RecyclerPool.LockFreePoolBase, RecyclerPool.NonRecyclingPoolBase, RecyclerPool.StatefulImplBase, RecyclerPool.ThreadLocalPoolBase

public interface RecyclerPool<P extends RecyclerPool.WithPool<P>> extends Serializable
API for object pools that control creation and possible reuse of objects that are costly to create (often things like encoding/decoding buffers).

Also contains partial (base) implementations for pools that use different strategies on retaining objects for reuse. Following implementations are included:

Default implementations are also included as nested classes.

Since:
2.16
  • Method Details

    • acquireAndLinkPooled

      default P acquireAndLinkPooled()
      Method called to acquire a Pooled value from this pool AND make sure it is linked back to this RecyclerPool as necessary for it to be released (see releasePooled(P)) later after usage ends. Actual acquisition is done by a call to acquirePooled().

      Default implementation calls acquirePooled() followed by a call to RecyclerPool.WithPool.withPool(com.fasterxml.jackson.core.util.RecyclerPool<P>).

      Returns:
      Pooled instance for caller to use; caller expected to call releasePooled(P) after it is done using instance.
    • acquirePooled

      P acquirePooled()
      Method for sub-classes to implement for actual acquire logic; called by acquireAndLinkPooled().
      Returns:
      Instance acquired (pooled or just constructed)
    • releasePooled

      void releasePooled(P pooled)
      Method that should be called when previously acquired (see acquireAndLinkPooled()) pooled value that is no longer needed; this lets pool to take ownership for possible reuse.
      Parameters:
      pooled - Pooled instance to release back to pool
    • clear

      default boolean clear()
      Optional method that may allow dropping of all pooled Objects; mostly useful for unbounded pool implementations that may retain significant memory and that may then be cleared regularly.
      Returns:
      true If pool supports operation and dropped all pooled Objects; false otherwise.
      Since:
      2.17
    • pooledCount

      default int pooledCount()
      Diagnostic method for obtaining an estimate of number of pooled items this pool contains, available for recycling. Note that in addition to this information possibly not being available (denoted by return value of -1) even when available this may be just an approximation.

      Default method implementation simply returns -1 and is meant to be overridden by concrete sub-classes.

      Returns:
      Number of pooled entries available from this pool, if available; -1 if not.
      Since:
      2.18