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.BoundedPoolBase<P extends RecyclerPool.
|
| public abstract static class | RecyclerPool.ConcurrentDequePoolBase<P extends RecyclerPool.
|
| public abstract static class | RecyclerPool.LockFreePoolBase<P extends RecyclerPool.
|
| public abstract static class | RecyclerPool.NonRecyclingPoolBase<P extends RecyclerPool.
|
| public abstract static class | RecyclerPool.StatefulImplBase<P extends 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.ThreadLocalPoolBase<P extends RecyclerPool.
Default |
| public static interface | RecyclerPool.WithPool<
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 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
| |
| 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. acquireAndLinkPooled().
|
| public int | |
| public void | releasePooled(P
Pooled instance to release back to pool pooled)Implements com. acquireAndLinkPooled)
pooled value that is no longer needed; this lets pool to take ownership
for possible reuse.
|
| 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() | |
| 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. acquireAndLinkPooled().
|
| public void | releasePooled(P
Pooled instance to release back to pool pooled)Implements com. acquireAndLinkPooled)
pooled value that is no longer needed; this lets pool to take ownership
for possible reuse.
|
| 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
| |
| 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
a lock free linked list for recycling instances.
Pool is unbounded: see RecyclerPool for
details on what this means.
| 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. acquireAndLinkPooled().
|
| public void | releasePooled(P
Pooled instance to release back to pool pooled)Implements com. acquireAndLinkPooled)
pooled value that is no longer needed; this lets pool to take ownership
for possible reuse.
|
| 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
| |
| 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. RecyclerPool as necessary for it to be
released (see releasePooled) later after usage ends.
|
| public abstract P | acquirePooled()
Redeclares com. acquireAndLinkPooled().
|
| public void | releasePooled(P
Pooled instance to release back to pool pooled)Implements com. acquireAndLinkPooled)
pooled value that is no longer needed; this lets pool to take ownership
for possible reuse.
|
| 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
| |
| 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. RecyclerPool as necessary for it to be
released (see releasePooled) later after usage ends.
|
| public abstract P | acquirePooled()
Redeclares com. acquireAndLinkPooled().
|
| public void | releasePooled(P
Pooled instance to release back to pool pooled)Implements com. acquireAndLinkPooled)
pooled value that is no longer needed; this lets pool to take ownership
for possible reuse.
|
| 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
| |
| 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
| |