Also contains partial (base) implementations for pools that use different strategies on retaining objects for reuse. Following implementations are included:
NonRecyclingPoolBase which does not retain or recycle anything and
will always simply construct and return new instance when
acquireBufferRecycler is called
ThreadLocalPoolBase which uses ThreadLocal to retain at most
1 object per Thread.
BoundedPoolBase is "bounded pool" and retains at most N objects (default value being
BoundedPoolBase#DEFAULT_CAPACITY) at any given time.
ConcurrentDequePoolBase, LockFreePoolBase
-- are "unbounded" and retain any number of objects released: in practice
it is at most the highest number of concurrently used BufferRecyclers.
Default implementations are also included as nested classes.
| Modifier and Type | Class and Description |
|---|---|
| public abstract static class | RecyclerPool.
|
| public abstract static class | RecyclerPool.
|
| public abstract static class | RecyclerPool.
Deprecated
Since 2.18: use other implementations
RecyclerPool implementation that uses
a lock free linked list for recycling instances.
|
| public abstract static class | RecyclerPool.
|
| public abstract static class | RecyclerPool.
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.
Default |
| public static interface | RecyclerPool.
Self type P extends RecyclerPool.Simple add-on interface that poolable entities must implement. |
| Modifier and Type | Method and Description |
|---|---|
| public default P | Returns: Pooled instance for caller to use; caller expected to callreleasePooled after it is done using instance.Method called to acquire a Pooled value from this pool
AND make sure it is linked back to this
|
| public P | Returns: Instance acquired (pooled or just constructed)Method for sub-classes to implement for actual acquire logic; called
by |
| public default boolean | Returns: true If pool supports operation and dropped all pooled
Objects; false otherwise.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.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 | back 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
Default implementation calls
| |
| acquirePooled | back to summary |
|---|---|
| public P acquirePooled() Method for sub-classes to implement for actual acquire logic; called
by
| |
| clear | back 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.
| |
| pooledCount | back 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
Default method implementation simply returns
| |
| releasePooled | back to summary |
|---|---|
| public void releasePooled(P pooled) Method that should be called when previously acquired (see
| |
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.
| Modifier and Type | Field 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 | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public P | acquirePooled()
Implements com. Method for sub-classes to implement for actual acquire logic; called
by |
| public int | |
| public boolean | clear()
Overrides default com. 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 com. 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)Implements com. Method that should be called when previously acquired (see |
| capacity | back to summary |
|---|---|
| private final transient int capacity | |
| DEFAULT_CAPACITY | back to summary |
|---|---|
| public static final int DEFAULT_CAPACITY Default capacity which limits number of items that are ever retained for reuse. | |
| pool | back to summary |
|---|---|
| private final transient ArrayBlockingQueue<P> pool | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides com. | |
| BoundedPoolBase | back to summary |
|---|---|
| protected BoundedPoolBase(int capacityAsId) | |
| acquirePooled | back to summary |
|---|---|
| public P acquirePooled() Implements com. Doc from com. Method for sub-classes to implement for actual acquire logic; called
by
| |
| capacity | back to summary |
|---|---|
| public int capacity() | |
| clear | back to summary |
|---|---|
| public boolean clear() Overrides default com. Doc from com. 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.
| |
| pooledCount | back to summary |
|---|---|
| public int pooledCount() Overrides default com. Doc from com. 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
Default method implementation simply returns
| |
| releasePooled | back to summary |
|---|---|
| public void releasePooled(P pooled) Implements com. Doc from com. Method that should be called when previously acquired (see
| |
RecyclerPool implementation that uses
ConcurrentLinkedDeque for recycling instances.
Pool is unbounded: see RecyclerPool what this means.
| Modifier and Type | Field and Description |
|---|---|
| protected final transient Deque | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public P | acquirePooled()
Implements com. Method for sub-classes to implement for actual acquire logic; called
by |
| public boolean | clear()
Overrides default com. 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 com. 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)Implements com. Method that should be called when previously acquired (see |
| pool | back to summary |
|---|---|
| protected final transient Deque<P> pool | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides com. | |
| ConcurrentDequePoolBase | back to summary |
|---|---|
| protected ConcurrentDequePoolBase(int serialization) | |
| acquirePooled | back to summary |
|---|---|
| public P acquirePooled() Implements com. Doc from com. Method for sub-classes to implement for actual acquire logic; called
by
| |
| clear | back to summary |
|---|---|
| public boolean clear() Overrides default com. Doc from com. 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.
| |
| pooledCount | back to summary |
|---|---|
| public int pooledCount() Overrides default com. Doc from com. 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
Default method implementation simply returns
| |
| releasePooled | back to summary |
|---|---|
| public void releasePooled(P pooled) Implements com. Doc from com. Method that should be called when previously acquired (see
| |
Deprecated
Since 2.18: use other implementations
RecyclerPool implementation that uses
a lock free linked list for recycling instances.
Pool is unbounded: see RecyclerPool for
details on what this means.Note
serious issues found with 2.17.0 lead to deprecation of this implementation -- basically it is possible to have unbalanced acquire/release success rate lead to excessive growth of pooled instances. See jackson-core#1260 for details.
| Modifier and Type | Class and Description |
|---|---|
| protected static class |
| Modifier and Type | Field and Description |
|---|---|
| private final transient AtomicReference | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public P | acquirePooled()
Implements com. Method for sub-classes to implement for actual acquire logic; called
by |
| public boolean | clear()
Overrides default com. 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 com. 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)Implements com. Method that should be called when previously acquired (see |
| head | back to summary |
|---|---|
| private final transient AtomicReference<RecyclerPool. | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides com. | |
| LockFreePoolBase | back to summary |
|---|---|
| protected LockFreePoolBase(int serialization) | |
| acquirePooled | back to summary |
|---|---|
| public P acquirePooled() Implements com. Doc from com. Method for sub-classes to implement for actual acquire logic; called
by
| |
| clear | back to summary |
|---|---|
| public boolean clear() Overrides default com. Doc from com. 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.
| |
| pooledCount | back to summary |
|---|---|
| public int pooledCount() Overrides default com. Doc from com. 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
Default method implementation simply returns
| |
| releasePooled | back to summary |
|---|---|
| public void releasePooled(P pooled) Implements com. Doc from com. Method that should be called when previously acquired (see
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv RecyclerPool. | |
| pack-priv final P |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| next | back to summary |
|---|---|
| pack-priv RecyclerPool. | |
| value | back to summary |
|---|---|
| pack-priv final P value | |
| Node | back to summary |
|---|---|
| pack-priv Node(P value) | |
RecyclerPool implementation that does not use
any pool but simply creates new instances when necessary.
| Modifier and Type | Field and Description |
|---|---|
| private static final long |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public P | acquireAndLinkPooled()
Overrides default com. Method called to acquire a Pooled value from this pool
AND make sure it is linked back to this
|
| public abstract P | acquirePooled()
Redeclares com. Method for sub-classes to implement for actual acquire logic; called
by |
| public boolean | Returns: Always returnstrueOverrides default com. Although no pooling occurs, we consider clearing to succeed,
so returns always |
| public int | pooledCount()
Overrides default com. 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)Implements com. Method that should be called when previously acquired (see |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| NonRecyclingPoolBase | back to summary |
|---|---|
| public NonRecyclingPoolBase() | |
| acquireAndLinkPooled | back to summary |
|---|---|
| public P acquireAndLinkPooled() Overrides default com. Doc from com. Method called to acquire a Pooled value from this pool
AND make sure it is linked back to this
Default implementation calls
| |
| acquirePooled | back to summary |
|---|---|
| public abstract P acquirePooled() Redeclares com. Doc from com. Method for sub-classes to implement for actual acquire logic; called
by
| |
| clear | back to summary |
|---|---|
| public boolean clear() Overrides default com. Although no pooling occurs, we consider clearing to succeed,
so returns always
| |
| pooledCount | back to summary |
|---|---|
| public int pooledCount() Overrides default com. Doc from com. 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
Default method implementation simply returns
| |
| releasePooled | back to summary |
|---|---|
| public void releasePooled(P pooled) Implements com. Doc from com. Method that should be called when previously acquired (see
| |
| Modifier and Type | Field 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 |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| protected Optional | |
| public abstract P |
| _serialization | back 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_SHARED | back to summary |
|---|---|
| public static final int SERIALIZATION_NON_SHARED | |
| SERIALIZATION_SHARED | back to summary |
|---|---|
| public static final int SERIALIZATION_SHARED | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| StatefulImplBase | back to summary |
|---|---|
| protected StatefulImplBase(int serialization) | |
| _resolveToShared | back to summary |
|---|---|
| protected Optional | |
| createPooled | back to summary |
|---|---|
| public abstract P createPooled() | |
RecyclerPool implementation that uses
ThreadLocal for recycling instances.
Instances are stored using java.lang.ref.SoftReference s so that
they may be Garbage Collected as needed by JVM.
Note that this implementation may not work well on platforms where
java.s are not well supported (like
Android), or on platforms where java.s are not
long-living or reused (like Project Loom).
| Modifier and Type | Field and Description |
|---|---|
| private static final long |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public P | acquireAndLinkPooled()
Overrides default com. Method called to acquire a Pooled value from this pool
AND make sure it is linked back to this
|
| public abstract P | acquirePooled()
Redeclares com. Method for sub-classes to implement for actual acquire logic; called
by |
| public boolean | clear()
Overrides default com. 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 com. 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)Implements com. Method that should be called when previously acquired (see |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| ThreadLocalPoolBase | back to summary |
|---|---|
| protected ThreadLocalPoolBase() | |
| acquireAndLinkPooled | back to summary |
|---|---|
| public P acquireAndLinkPooled() Overrides default com. Doc from com. Method called to acquire a Pooled value from this pool
AND make sure it is linked back to this
Default implementation calls
| |
| acquirePooled | back to summary |
|---|---|
| public abstract P acquirePooled() Redeclares com. Doc from com. Method for sub-classes to implement for actual acquire logic; called
by
| |
| clear | back to summary |
|---|---|
| public boolean clear() Overrides default com. Doc from com. 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.
| |
| pooledCount | back to summary |
|---|---|
| public int pooledCount() Overrides default com. Doc from com. 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
Default method implementation simply returns
| |
| releasePooled | back to summary |
|---|---|
| public void releasePooled(P pooled) Implements com. Doc from com. Method that should be called when previously acquired (see
| |
| Modifier and Type | Method 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)Pool that "owns" pooled item pool)Method to call to add link from pooled item back to pool that handles it |
| releaseToPool | back to summary |
|---|---|
| public void releaseToPool() Method called when this item is to be released back to the pool that owns it (if any) | |
| withPool | back to summary |
|---|---|
| public P withPool(RecyclerPool<P> pool) Method to call to add link from pooled item back to pool that handles it
| |