T - the type of objects held in the observable object poolpublic class SamplingPoolReducer<T> 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 a RuntimeException or an Error 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(PoolService<T> poolService,
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 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(PoolService<T> poolService, long timeInterval, TimeUnit unit, int samples)
SamplingPoolReducer with the given PoolService and
timeInterval settings. The created pool reducer is not started and needs to be
explicitly started via calling the start() method.poolService - the pool service which 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 poolServiceunit - 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 poolServiceIllegalArgumentException - if one of the following holds:poolService == null || timeInterval <= 0 || unit == null || samples <= 0public void start()
start in interface ThreadedPoolReducerprotected 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 a RuntimeException or an Error, 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, in this case it will be
a RuntimeException or an Errorpublic Thread.State getState()
getState in interface ThreadedPoolReducerpublic void terminate()
terminate in interface ThreadedPoolReducerCopyright © 2013-2016 vibur.org. All Rights Reserved.