- 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.
A thread-local caching is also available, disabled by default, that is useful when entries are acquired and released by the same thread, but hampering performance when entries are acquired by one thread but released by a different thread.
-
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 org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainerNested classes/interfaces inherited from interface org.eclipse.jetty.util.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 and noThreadLocalcache.ConcurrentPool(ConcurrentPool.StrategyType strategyType, int maxSize, boolean cache) Creates an instance with the specified strategy and an optionalThreadLocalcache.ConcurrentPool(ConcurrentPool.StrategyType strategyType, int maxSize, boolean cache, ToIntFunction<P> maxMultiplex) Creates an instance with the specified strategy, an optionalThreadLocalcache. -
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.intintbooleanreserve()Creates a new disabled slot into the pool.intsize()stream()Terminates thisPool.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.eclipse.jetty.util.Pool
acquire, getIdleCount, getInUseCount, getReservedCount
-
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 and no
ThreadLocalcache.- Parameters:
strategyType- the strategy to used to lookup entriesmaxSize- the maximum number of pooled entries
-
ConcurrentPool
Creates an instance with the specified strategy and an optional
ThreadLocalcache.- 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
public ConcurrentPool(ConcurrentPool.StrategyType strategyType, int maxSize, boolean cache, ToIntFunction<P> maxMultiplex) Creates an instance with the specified strategy, an optional
ThreadLocalcache. 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
-
-
Method Details
-
getTerminatedCount
public int getTerminatedCount()- Specified by:
getTerminatedCountin interfacePool<P>- Returns:
- the number of terminated entries
-
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
public int size() -
getMaxSize
public int getMaxSize()- Specified by:
getMaxSizein interfacePool<P>- Returns:
- the maximum number of entries in this
Pool
-
stream
-
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
-