Top Description Inners Methods
tools.jackson.core.util

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

extends Serializable
Known Direct Implementers
tools.jackson.core.util.RecyclerPool.ThreadLocalPoolBase, tools.jackson.core.util.RecyclerPool.NonRecyclingPoolBase, tools.jackson.core.util.RecyclerPool.StatefulImplBase
Type Parameters
<P>
Type of Objects pool recycles
Imports
java.io.Serializable, java.util.Deque, .Optional, java.util.concurrent.ArrayBlockingQueue, .ConcurrentLinkedDeque

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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public abstract static class
RecyclerPool.BoundedPoolBase<P extends RecyclerPool.WithPool<P>>

RecyclerPool implementation that uses a bounded queue (ArrayBlockingQueue for recycling instances.

public abstract static class
RecyclerPool.ConcurrentDequePoolBase<P extends RecyclerPool.WithPool<P>>

RecyclerPool implementation that uses ConcurrentLinkedDeque for recycling instances.

public abstract static class
RecyclerPool.NonRecyclingPoolBase<P extends RecyclerPool.WithPool<P>>

RecyclerPool implementation that does not use any pool but simply creates new instances when necessary.

public abstract static class
RecyclerPool.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.

public abstract static class
RecyclerPool.ThreadLocalPoolBase<P extends RecyclerPool.WithPool<P>>

Default RecyclerPool implementation that uses ThreadLocal for recycling instances.

public static interface
RecyclerPool.WithPool<
Self type
P extends RecyclerPool.WithPool<P>
>

Simple add-on interface that poolable entities must implement.

Method Summary

Modifier and TypeMethod and Description
public default P

Returns:

Pooled instance for caller to use; caller expected to call releasePooled after it is done using instance.
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) later after usage ends.

public P

Returns:

Instance acquired (pooled or just constructed)
acquirePooled
()

Method for sub-classes to implement for actual acquire logic; called by acquireAndLinkPooled().

public default boolean

Returns:

true If pool supports operation and dropped all pooled Objects; false otherwise.
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.

public default int

Returns:

Number of pooled entries available from this pool, if available; -1 if not.
pooledCount
()

Diagnostic method for obtaining an estimate of number of pooled items this pool contains, available for recycling.

public void
releasePooled(P
Pooled instance to release back to pool
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.

Method Detail

acquireAndLinkPooledback to summary
public 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) later after usage ends. Actual acquisition is done by a call to acquirePooled().

Default implementation calls acquirePooled() followed by a call to WithPool#withPool.

Returns:P

Pooled instance for caller to use; caller expected to call releasePooled after it is done using instance.

acquirePooledback to summary
public P acquirePooled()

Method for sub-classes to implement for actual acquire logic; called by acquireAndLinkPooled().

Returns:P

Instance acquired (pooled or just constructed)

clearback to summary
public 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:boolean

true If pool supports operation and dropped all pooled Objects; false otherwise.

Since
2.17
pooledCountback to summary
public 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:int

Number of pooled entries available from this pool, if available; -1 if not.

Since
2.18
releasePooledback to summary
public 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:P

Pooled instance to release back to pool

tools.jackson.core.util back to summary

public abstract Class RecyclerPool.BoundedPoolBase<P extends RecyclerPool.WithPool<P>>

extends RecyclerPool.StatefulImplBase<P extends RecyclerPool.WithPool<P>>
Class Inheritance
Known Direct Subclasses
tools.jackson.core.util.JsonRecyclerPools.BoundedPool

RecyclerPool implementation that uses a bounded queue (ArrayBlockingQueue for recycling instances. This is "bounded" pool since it will never hold on to more pooled instances than its size configuration: the default size is BoundedPoolBase#DEFAULT_CAPACITY.

Field Summary

Modifier and TypeField and Description
private final transient int
public static final int
DEFAULT_CAPACITY

Default capacity which limits number of items that are ever retained for reuse.

private final transient ArrayBlockingQueue<P>
private static final long
Inherited from tools.jackson.core.util.RecyclerPool.StatefulImplBase:
_serializationSERIALIZATION_NON_SHAREDSERIALIZATION_SHARED

Constructor Summary

AccessConstructor and Description
protected
BoundedPoolBase(int capacityAsId)

Method Summary

Modifier and TypeMethod and Description
public P
acquirePooled()

Implements tools.jackson.core.util.RecyclerPool.acquirePooled.

Method for sub-classes to implement for actual acquire logic; called by acquireAndLinkPooled().

public int
public boolean
clear()

Overrides default tools.jackson.core.util.RecyclerPool.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.

public int
pooledCount()

Overrides default tools.jackson.core.util.RecyclerPool.pooledCount.

Diagnostic method for obtaining an estimate of number of pooled items this pool contains, available for recycling.

public void
releasePooled(P pooled)

Implements tools.jackson.core.util.RecyclerPool.releasePooled.

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.

Inherited from tools.jackson.core.util.RecyclerPool.StatefulImplBase:
_resolveToSharedcreatePooled

Field Detail

capacityback to summary
private final transient int capacity
DEFAULT_CAPACITYback to summary
public static final int DEFAULT_CAPACITY

Default capacity which limits number of items that are ever retained for reuse.

poolback to summary
private final transient ArrayBlockingQueue<P> pool
serialVersionUIDback to summary
private static final long serialVersionUID

Hides tools.jackson.core.util.RecyclerPool.StatefulImplBase.serialVersionUID.

Constructor Detail

BoundedPoolBaseback to summary
protected BoundedPoolBase(int capacityAsId)

Method Detail

acquirePooledback to summary
public P acquirePooled()

Implements tools.jackson.core.util.RecyclerPool.acquirePooled.

Doc from tools.jackson.core.util.RecyclerPool.acquirePooled.

Method for sub-classes to implement for actual acquire logic; called by acquireAndLinkPooled().

Annotations
@Override
capacityback to summary
public int capacity()
clearback to summary
public boolean clear()

Overrides default tools.jackson.core.util.RecyclerPool.clear.

Doc from tools.jackson.core.util.RecyclerPool.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.

Annotations
@Override
pooledCountback to summary
public int pooledCount()

Overrides default tools.jackson.core.util.RecyclerPool.pooledCount.

Doc from tools.jackson.core.util.RecyclerPool.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.

Annotations
@Override
releasePooledback to summary
public void releasePooled(P pooled)

Implements tools.jackson.core.util.RecyclerPool.releasePooled.

Doc from tools.jackson.core.util.RecyclerPool.releasePooled.

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.

Annotations
@Override
tools.jackson.core.util back to summary

public abstract Class RecyclerPool.ConcurrentDequePoolBase<P extends RecyclerPool.WithPool<P>>

extends RecyclerPool.StatefulImplBase<P extends RecyclerPool.WithPool<P>>
Class Inheritance
Known Direct Subclasses
tools.jackson.core.util.JsonRecyclerPools.ConcurrentDequePool

RecyclerPool implementation that uses ConcurrentLinkedDeque for recycling instances.

Pool is unbounded: see RecyclerPool what this means.

Field Summary

Modifier and TypeField and Description
protected final transient Deque<P>
private static final long
Inherited from tools.jackson.core.util.RecyclerPool.StatefulImplBase:
_serializationSERIALIZATION_NON_SHAREDSERIALIZATION_SHARED

Constructor Summary

AccessConstructor and Description
protected
ConcurrentDequePoolBase(int serialization)

Method Summary

Modifier and TypeMethod and Description
public P
acquirePooled()

Implements tools.jackson.core.util.RecyclerPool.acquirePooled.

Method for sub-classes to implement for actual acquire logic; called by acquireAndLinkPooled().

public boolean
clear()

Overrides default tools.jackson.core.util.RecyclerPool.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.

public int
pooledCount()

Overrides default tools.jackson.core.util.RecyclerPool.pooledCount.

Diagnostic method for obtaining an estimate of number of pooled items this pool contains, available for recycling.

public void
releasePooled(P pooled)

Implements tools.jackson.core.util.RecyclerPool.releasePooled.

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.

Inherited from tools.jackson.core.util.RecyclerPool.StatefulImplBase:
_resolveToSharedcreatePooled

Field Detail

poolback to summary
protected final transient Deque<P> pool
serialVersionUIDback to summary
private static final long serialVersionUID

Hides tools.jackson.core.util.RecyclerPool.StatefulImplBase.serialVersionUID.

Constructor Detail

ConcurrentDequePoolBaseback to summary
protected ConcurrentDequePoolBase(int serialization)

Method Detail

acquirePooledback to summary
public P acquirePooled()

Implements tools.jackson.core.util.RecyclerPool.acquirePooled.

Doc from tools.jackson.core.util.RecyclerPool.acquirePooled.

Method for sub-classes to implement for actual acquire logic; called by acquireAndLinkPooled().

Annotations
@Override
clearback to summary
public boolean clear()

Overrides default tools.jackson.core.util.RecyclerPool.clear.

Doc from tools.jackson.core.util.RecyclerPool.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.

Annotations
@Override
pooledCountback to summary
public int pooledCount()

Overrides default tools.jackson.core.util.RecyclerPool.pooledCount.

Doc from tools.jackson.core.util.RecyclerPool.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.

Annotations
@Override
releasePooledback to summary
public void releasePooled(P pooled)

Implements tools.jackson.core.util.RecyclerPool.releasePooled.

Doc from tools.jackson.core.util.RecyclerPool.releasePooled.

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.

Annotations
@Override
tools.jackson.core.util back to summary

public abstract Class RecyclerPool.NonRecyclingPoolBase<P extends RecyclerPool.WithPool<P>>

extends Object
implements RecyclerPool<P extends RecyclerPool.WithPool<P>>
Class Inheritance
All Implemented Interfaces
tools.jackson.core.util.RecyclerPool, java.io.Serializable
Known Direct Subclasses
tools.jackson.core.util.JsonRecyclerPools.NonRecyclingPool

RecyclerPool implementation that does not use any pool but simply creates new instances when necessary.

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public P
acquireAndLinkPooled()

Overrides default tools.jackson.core.util.RecyclerPool.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) later after usage ends.

public abstract P
acquirePooled()

Redeclares tools.jackson.core.util.RecyclerPool.acquirePooled.

Method for sub-classes to implement for actual acquire logic; called by acquireAndLinkPooled().

public boolean

Returns:

Always returns true
clear
()

Overrides default tools.jackson.core.util.RecyclerPool.clear.

Although no pooling occurs, we consider clearing to succeed, so returns always true.

public int
pooledCount()

Overrides default tools.jackson.core.util.RecyclerPool.pooledCount.

Diagnostic method for obtaining an estimate of number of pooled items this pool contains, available for recycling.

public void
releasePooled(P pooled)

Implements tools.jackson.core.util.RecyclerPool.releasePooled.

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.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

NonRecyclingPoolBaseback to summary
public NonRecyclingPoolBase()

Method Detail

acquireAndLinkPooledback to summary
public P acquireAndLinkPooled()

Overrides default tools.jackson.core.util.RecyclerPool.acquireAndLinkPooled.

Doc from tools.jackson.core.util.RecyclerPool.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) later after usage ends. Actual acquisition is done by a call to acquirePooled().

Default implementation calls acquirePooled() followed by a call to WithPool#withPool.

Annotations
@Override
acquirePooledback to summary
public abstract P acquirePooled()

Redeclares tools.jackson.core.util.RecyclerPool.acquirePooled.

Doc from tools.jackson.core.util.RecyclerPool.acquirePooled.

Method for sub-classes to implement for actual acquire logic; called by acquireAndLinkPooled().

Annotations
@Override
clearback to summary
public boolean clear()

Overrides default tools.jackson.core.util.RecyclerPool.clear.

Although no pooling occurs, we consider clearing to succeed, so returns always true.

Returns:boolean

Always returns true

Annotations
@Override
pooledCountback to summary
public int pooledCount()

Overrides default tools.jackson.core.util.RecyclerPool.pooledCount.

Doc from tools.jackson.core.util.RecyclerPool.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.

Annotations
@Override
releasePooledback to summary
public void releasePooled(P pooled)

Implements tools.jackson.core.util.RecyclerPool.releasePooled.

Doc from tools.jackson.core.util.RecyclerPool.releasePooled.

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.

Annotations
@Override
tools.jackson.core.util back to summary

public abstract Class RecyclerPool.StatefulImplBase<P extends RecyclerPool.WithPool<P>>

extends Object
implements RecyclerPool<P extends RecyclerPool.WithPool<P>>
Class Inheritance
All Implemented Interfaces
tools.jackson.core.util.RecyclerPool, java.io.Serializable
Known Direct Subclasses
tools.jackson.core.util.RecyclerPool.ConcurrentDequePoolBase, tools.jackson.core.util.RecyclerPool.BoundedPoolBase

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.

Field Summary

Modifier and TypeField and Description
protected final int
_serialization

Value that indicates basic aspects of pool for JDK serialization; either marker for shared/non-shared, or possibly bounded size; depends on sub-class.

public static final int
public static final int
private static final long

Constructor Summary

AccessConstructor and Description
protected
StatefulImplBase(int serialization)

Method Summary

Modifier and TypeMethod and Description
protected Optional<RecyclerPool.StatefulImplBase<P>>
public abstract P
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_serializationback to summary
protected final int _serialization

Value that indicates basic aspects of pool for JDK serialization; either marker for shared/non-shared, or possibly bounded size; depends on sub-class.

SERIALIZATION_NON_SHAREDback to summary
public static final int SERIALIZATION_NON_SHARED
SERIALIZATION_SHAREDback to summary
public static final int SERIALIZATION_SHARED
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

StatefulImplBaseback to summary
protected StatefulImplBase(int serialization)

Method Detail

_resolveToSharedback to summary
protected Optional<RecyclerPool.StatefulImplBase<P>> _resolveToShared(RecyclerPool.StatefulImplBase<P> shared)
createPooledback to summary
public abstract P createPooled()
tools.jackson.core.util back to summary

public abstract Class RecyclerPool.ThreadLocalPoolBase<P extends RecyclerPool.WithPool<P>>

extends Object
implements RecyclerPool<P extends RecyclerPool.WithPool<P>>
Class Inheritance
All Implemented Interfaces
tools.jackson.core.util.RecyclerPool, java.io.Serializable
Known Direct Subclasses
tools.jackson.core.util.JsonRecyclerPools.ThreadLocalPool

Default RecyclerPool implementation that uses ThreadLocal for recycling instances. Instances are stored using java.lang.ref.SoftReferences so that they may be Garbage Collected as needed by JVM.

Note that this implementation may not work well on platforms where java.lang.ref.SoftReferences are not well supported (like Android), or on platforms where java.lang.Threads are not long-living or reused (like Project Loom).

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public P
acquireAndLinkPooled()

Overrides default tools.jackson.core.util.RecyclerPool.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) later after usage ends.

public abstract P
acquirePooled()

Redeclares tools.jackson.core.util.RecyclerPool.acquirePooled.

Method for sub-classes to implement for actual acquire logic; called by acquireAndLinkPooled().

public boolean
clear()

Overrides default tools.jackson.core.util.RecyclerPool.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.

public int
pooledCount()

Overrides default tools.jackson.core.util.RecyclerPool.pooledCount.

Diagnostic method for obtaining an estimate of number of pooled items this pool contains, available for recycling.

public void
releasePooled(P pooled)

Implements tools.jackson.core.util.RecyclerPool.releasePooled.

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.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

ThreadLocalPoolBaseback to summary
protected ThreadLocalPoolBase()

Method Detail

acquireAndLinkPooledback to summary
public P acquireAndLinkPooled()

Overrides default tools.jackson.core.util.RecyclerPool.acquireAndLinkPooled.

Doc from tools.jackson.core.util.RecyclerPool.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) later after usage ends. Actual acquisition is done by a call to acquirePooled().

Default implementation calls acquirePooled() followed by a call to WithPool#withPool.

Annotations
@Override
acquirePooledback to summary
public abstract P acquirePooled()

Redeclares tools.jackson.core.util.RecyclerPool.acquirePooled.

Doc from tools.jackson.core.util.RecyclerPool.acquirePooled.

Method for sub-classes to implement for actual acquire logic; called by acquireAndLinkPooled().

Annotations
@Override
clearback to summary
public boolean clear()

Overrides default tools.jackson.core.util.RecyclerPool.clear.

Doc from tools.jackson.core.util.RecyclerPool.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.

Annotations
@Override
pooledCountback to summary
public int pooledCount()

Overrides default tools.jackson.core.util.RecyclerPool.pooledCount.

Doc from tools.jackson.core.util.RecyclerPool.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.

Annotations
@Override
releasePooledback to summary
public void releasePooled(P pooled)

Implements tools.jackson.core.util.RecyclerPool.releasePooled.

Doc from tools.jackson.core.util.RecyclerPool.releasePooled.

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.

Annotations
@Override
tools.jackson.core.util back to summary

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

Known Direct Implementers
tools.jackson.core.util.BufferRecycler
Type Parameters
<P>
Self type

Simple add-on interface that poolable entities must implement.

Method Summary

Modifier and TypeMethod and Description
public void
releaseToPool()

Method called when this item is to be released back to the pool that owns it (if any)

public P

Returns:

This item (for call chaining)
withPool
(RecyclerPool<P>
Pool that "owns" pooled item
pool
)

Method to call to add link from pooled item back to pool that handles it

Method Detail

releaseToPoolback to summary
public void releaseToPool()

Method called when this item is to be released back to the pool that owns it (if any)

withPoolback to summary
public P withPool(RecyclerPool<P> pool)

Method to call to add link from pooled item back to pool that handles it

Parameters
pool:RecyclerPool<P>

Pool that "owns" pooled item

Returns:P

This item (for call chaining)