Class ConcurrentPool<P>
- Type Parameters:
P- the type of the pooled objects
A concurrent implementation of Pool.
This implementation offers a number of strategies
used to select the entry returned from acquire(), and its
capacity is bounded to a max size.
When a pooled item is acquired from this pool, it is only held
by a WeakReference, so that if it is collected before being released,
then that leak is detected and the entry is removed (see getLeaked().
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA Pool entry that holds metadata and a pooled object.static enumThe type of the strategy to use for the pool.Nested classes/interfaces inherited from interface Dumpable
Dumpable.DumpableContainerNested classes/interfaces inherited from interface Pool
Pool.Entry<E>, Pool.Factory<F>, Pool.Wrapper<W> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intConcurrentPoolinternally needs to linearly scan a list to perform an acquisition. -
Constructor Summary
ConstructorsConstructorDescriptionConcurrentPool(ConcurrentPool.StrategyType strategyType, int maxSize) Creates an instance with the specified strategy.ConcurrentPool(ConcurrentPool.StrategyType strategyType, int maxSize, boolean cache) Deprecated, for removal: This API element is subject to removal in a future version.cache is no longer supported.ConcurrentPool(ConcurrentPool.StrategyType strategyType, int maxSize, boolean cache, ToIntFunction<P> maxMultiplex) Deprecated, for removal: This API element is subject to removal in a future version.cache is no longer supported.ConcurrentPool(ConcurrentPool.StrategyType strategyType, int maxSize, ToIntFunction<P> maxMultiplex) Creates an instance with the specified strategy. and a function that returns the max multiplex count for a given pooled object. -
Method Summary
Modifier and TypeMethodDescriptionacquire()Acquires an entry from the pool.voiddump(Appendable out, String indent) Dump this object (and children) into an Appendable using the provided indent after any new lines.intintlongintintintbooleanprotected voidleaked()reserve()Creates a new disabled slot into the pool.intsize()stream()Terminates thisPool.toString()
-
Field Details
-
OPTIMAL_MAX_SIZE
public static final int OPTIMAL_MAX_SIZEConcurrentPoolinternally needs to linearly scan a list to perform an acquisition. This list needs to be reasonably short otherwise there is a risk that scanning the list becomes a bottleneck. Instances created with a size at most this value should be immune to this problem.- See Also:
-
-
Constructor Details
-
ConcurrentPool
Creates an instance with the specified strategy.
- Parameters:
strategyType- the strategy to used to lookup entriesmaxSize- the maximum number of pooled entries
-
ConcurrentPool
@Deprecated(since="12.0.4", forRemoval=true) public ConcurrentPool(ConcurrentPool.StrategyType strategyType, int maxSize, boolean cache) Deprecated, for removal: This API element is subject to removal in a future version.cache is no longer supported. UseConcurrentPool.StrategyType.THREAD_IDCreates an instance with the specified strategy.
- Parameters:
strategyType- the strategy to used to lookup entriesmaxSize- the maximum number of pooled entriescache- whether aThreadLocalcache should be used for the most recently released entry
-
ConcurrentPool
@Deprecated(since="12.0.4", forRemoval=true) public ConcurrentPool(ConcurrentPool.StrategyType strategyType, int maxSize, boolean cache, ToIntFunction<P> maxMultiplex) Deprecated, for removal: This API element is subject to removal in a future version.cache is no longer supported. UseConcurrentPool.StrategyType.THREAD_IDCreates an instance with the specified strategy. and a function that returns the max multiplex count for a given pooled object.
- Parameters:
strategyType- the strategy to used to lookup entriesmaxSize- the maximum number of pooled entriescache- whether aThreadLocalcache should be used for the most recently released entrymaxMultiplex- a function that given the pooled object returns the max multiplex count
-
ConcurrentPool
public ConcurrentPool(ConcurrentPool.StrategyType strategyType, int maxSize, ToIntFunction<P> maxMultiplex) Creates an instance with the specified strategy. and a function that returns the max multiplex count for a given pooled object.
- Parameters:
strategyType- the strategy to used to lookup entriesmaxSize- the maximum number of pooled entriesmaxMultiplex- a function that given the pooled object returns the max multiplex count
-
-
Method Details
-
getLeaked
-
leaked
protected void leaked() -
reserve
Description copied from interface:PoolCreates a new disabled slot into the pool.
The returned entry must ultimately have the
Pool.Entry.enable(Object, boolean)method called or be removed viaPool.Entry.remove(). -
acquire
Description copied from interface:PoolAcquires an entry from the pool.
Only enabled entries will be returned from this method and their
Pool.Entry.enable(Object, boolean)method must not be called. -
isTerminated
public boolean isTerminated()- Specified by:
isTerminatedin interfacePool<P>- Returns:
- whether this
Poolhas been terminated - See Also:
-
terminate
Description copied from interface:PoolTerminates this
Pool.All the entries are marked as terminated and cannot be acquired nor released, but only removed.
The returned list of all entries may be iterated to perform additional operations on the pooled objects.
The pool cannot be used anymore after it is terminated.
-
size
-
getMaxSize
public int getMaxSize()- Specified by:
getMaxSizein interfacePool<P>- Returns:
- the maximum number of entries in this
Pool
-
stream
-
getReservedCount
public int getReservedCount()- Specified by:
getReservedCountin interfacePool<P>- Returns:
- the number of reserved entries
-
getIdleCount
public int getIdleCount()- Specified by:
getIdleCountin interfacePool<P>- Returns:
- the number of idle entries
-
getInUseCount
public int getInUseCount()- Specified by:
getInUseCountin interfacePool<P>- Returns:
- the number of in-use entries
-
getTerminatedCount
public int getTerminatedCount()- Specified by:
getTerminatedCountin interfacePool<P>- Returns:
- the number of terminated entries
-
dump
Description copied from interface:DumpableDump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.- Specified by:
dumpin interfaceDumpable- Parameters:
out- The appendable to dump toindent- The indent to apply after any new lines.- Throws:
IOException- if unable to write to Appendable
-
toString
-