public class SamplingPoolReducer extends Object implements ThreadedPoolReducer
This pool reducer will not bring the number of allocated on the pool
objects to less than the pool initial size.
This pool reducer creates one daemon service thread which will be started when
the reducer's start() method is called, and will be alive until the
terminate() method is called or until the calling application exits.
Note that if an exception is thrown by the overridable
afterReduce(int, int, Throwable) method hook, it will terminate the
SamplingPoolReducer, including the reducer's background daemon thread.
| Modifier and Type | Field and Description |
|---|---|
protected static double |
MAX_REDUCTION_FRACTION |
protected int |
minRemainingCreated |
| Constructor and Description |
|---|
SamplingPoolReducer(BasePool pool,
long timeInterval,
TimeUnit unit,
int samples)
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
afterReduce(int reduction,
int reduced,
Throwable thrown)
An after reduce pool hook.
|
protected int |
calculateReduction()
Calculates the number of currently allocated on the pool elements that needs to be destroyed/deallocated,
as a result of the stats collected during the just finished observational time period.
|
Thread.State |
getState()
Returns the state of the underlying thread.
|
protected String |
getThreadName() |
protected void |
reducePool() |
protected void |
samplePool() |
void |
start()
Starts this pool reducer, which starts its underlying daemon thread.
|
void |
terminate()
Terminates this pool reducer, which terminates its underlying daemon thread.
|
protected static final double MAX_REDUCTION_FRACTION
protected int minRemainingCreated
public SamplingPoolReducer(BasePool pool, long timeInterval, TimeUnit unit, int samples)
SamplingPoolReducer with the given BasePool and
timeInterval settings. The created pool reducer is not started and needs to be
explicitly started via calling the start() method.pool - the pool that is to be reduced if necessarytimeInterval - the time period after which the SamplingPoolReducer will try to
possibly reduce the number of created but unused objects in the
given poolunit - the time unit of the timeInterval argumentsamples - how many times the SamplingPoolReducer will wake up during the given
timeInterval period in order to sample various information from
the given poolIllegalArgumentException - if one of the following holds:timeInterval <= 0 || samples <= 0NullPointerException - if one of the following holds:pool == null || unit == nullpublic void start()
ThreadedPoolReducerstart in interface ThreadedPoolReducerprotected String getThreadName()
protected void samplePool()
protected void reducePool()
protected int calculateReduction()
initial
size as a result of this reduction.protected void afterReduce(int reduction,
int reduced,
Throwable thrown)
terminate() this pool reducer
if thrown != null. Note that if this method throws an exception, this
will terminate the pool reducer, too.reduction - the intended reduction numberreduced - the number of objects which were successfully removed/destroyed from the poolthrown - a thrown during the pool reduction exception if any.public Thread.State getState()
ThreadedPoolReducergetState in interface ThreadedPoolReducerpublic void terminate()
ThreadedPoolReducerterminate in interface ThreadedPoolReducerCopyright © 2013-2019 vibur.org. All Rights Reserved.