Package com.fasterxml.jackson.core.util
Interface RecyclerPool<P extends RecyclerPool.WithPool<P>>
-
- Type Parameters:
P- Type of Objects pool recycles
- All Superinterfaces:
java.io.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 java.io.SerializableAPI 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:
RecyclerPool.NonRecyclingPoolBasewhich does not retain or recycle anything and will always simply construct and return new instance whenacquireBufferRecycleris calledRecyclerPool.ThreadLocalPoolBasewhich usesThreadLocalto retain at most 1 object perThread.RecyclerPool.BoundedPoolBaseis "bounded pool" and retains at most N objects (default value beingRecyclerPool.BoundedPoolBase.DEFAULT_CAPACITY) at any given time.- Two implementations --
RecyclerPool.ConcurrentDequePoolBase,RecyclerPool.LockFreePoolBase-- are "unbounded" and retain any number of objects released: in practice it is at most the highest number of concurrently usedBufferRecyclers.
Default implementations are also included as nested classes.
- Since:
- 2.16
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classRecyclerPool.BoundedPoolBase<P extends RecyclerPool.WithPool<P>>RecyclerPoolimplementation that uses a bounded queue (ArrayBlockingQueuefor recycling instances.static classRecyclerPool.ConcurrentDequePoolBase<P extends RecyclerPool.WithPool<P>>RecyclerPoolimplementation that usesConcurrentLinkedDequefor recycling instances.static classRecyclerPool.LockFreePoolBase<P extends RecyclerPool.WithPool<P>>RecyclerPoolimplementation that uses a lock free linked list for recycling instances.static classRecyclerPool.NonRecyclingPoolBase<P extends RecyclerPool.WithPool<P>>RecyclerPoolimplementation that does not use any pool but simply creates new instances when necessary.static classRecyclerPool.StatefulImplBase<P extends RecyclerPool.WithPool<P>>Intermediate base class for instances that are stateful and require special handling with respect to JDK serialization, to retain "global" reference distinct from non-shared ones.static classRecyclerPool.ThreadLocalPoolBase<P extends RecyclerPool.WithPool<P>>DefaultRecyclerPoolimplementation that usesThreadLocalfor recycling instances.static interfaceRecyclerPool.WithPool<P extends RecyclerPool.WithPool<P>>Simple add-on interface that poolable entities must implement.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default PacquireAndLinkPooled()Method called to acquire a Pooled value from this pool AND make sure it is linked back to thisRecyclerPoolas necessary for it to be released (seereleasePooled(P)) later after usage ends.PacquirePooled()Method for sub-classes to implement for actual acquire logic; called byacquireAndLinkPooled().voidreleasePooled(P pooled)Method that should be called when previously acquired (seeacquireAndLinkPooled()) pooled value that is no longer needed; this lets pool to take ownership for possible reuse.
-
-
-
Method Detail
-
acquireAndLinkPooled
default P acquireAndLinkPooled()
Method called to acquire a Pooled value from this pool AND make sure it is linked back to thisRecyclerPoolas necessary for it to be released (seereleasePooled(P)) later after usage ends. Actual acquisition is done by a call toacquirePooled().Default implementation calls
acquirePooled()followed by a call toRecyclerPool.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 byacquireAndLinkPooled().- Returns:
- Instance acquired (pooled or just constructed)
-
releasePooled
void releasePooled(P pooled)
Method that should be called when previously acquired (seeacquireAndLinkPooled()) 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
-
-