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
Modifier and TypeClassDescriptionstatic class
A Pool entry that holds metadata and a pooled object.static enum
The type of the strategy to use for the pool.Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.Pool
Pool.Entry<E>, Pool.Factory<F>, Pool.Wrapper<W>
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
ConcurrentPool
internally needs to linearly scan a list to perform an acquisition. -
Constructor Summary
ConstructorDescriptionConcurrentPool
(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. -
Method Summary
Modifier and TypeMethodDescriptionacquire()
Acquires an entry from the pool.void
dump
(Appendable out, String indent) Dump this object (and children) into an Appendable using the provided indent after any new lines.int
int
long
int
int
int
boolean
protected void
leaked()
reserve()
Creates a new disabled slot into the pool.int
size()
stream()
Terminates thisPool
.toString()
-
Field Details
-
OPTIMAL_MAX_SIZE
public static final int OPTIMAL_MAX_SIZEConcurrentPool
internally 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_ID
Creates an instance with the specified strategy.
- Parameters:
strategyType
- the strategy to used to lookup entriesmaxSize
- the maximum number of pooled entriescache
- whether aThreadLocal
cache 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_ID
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 entriescache
- whether aThreadLocal
cache 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:Pool
Creates 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:Pool
Acquires 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:
isTerminated
in interfacePool<P>
- Returns:
- whether this
Pool
has been terminated - See Also:
-
terminate
Description copied from interface:Pool
Terminates 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
public int size() -
getMaxSize
public int getMaxSize()- Specified by:
getMaxSize
in interfacePool<P>
- Returns:
- the maximum number of entries in this
Pool
-
stream
-
getReservedCount
public int getReservedCount()- Specified by:
getReservedCount
in interfacePool<P>
- Returns:
- the number of reserved entries
-
getIdleCount
public int getIdleCount()- Specified by:
getIdleCount
in interfacePool<P>
- Returns:
- the number of idle entries
-
getInUseCount
public int getInUseCount()- Specified by:
getInUseCount
in interfacePool<P>
- Returns:
- the number of in-use entries
-
getTerminatedCount
public int getTerminatedCount()- Specified by:
getTerminatedCount
in interfacePool<P>
- Returns:
- the number of terminated entries
-
dump
Description copied from interface:Dumpable
Dump 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:
dump
in 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
-