public class SamplingPoolReducer extends Object implements ThreadedPoolReducer
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.
Important specific to be mentioned is that if an exception is thrown
during the pool reduction, which could be in this case a RuntimeException
or an
Error
, the default implementation of the overridable
afterReduce(int, int, Throwable)
method will simply rethrow the exception, which
will in turn terminate the reducer's background daemon thread.
Constructor and Description |
---|
SamplingPoolReducer(BasePoolService 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() |
Thread.State |
getState()
Returns the state of the underlying thread.
|
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.
|
public SamplingPoolReducer(BasePoolService poolService, long timeInterval, TimeUnit unit, int samples)
SamplingPoolReducer
with the given BasePoolService
and
timeInterval
settings. The created pool reducer is not started and needs to be
explicitly started via call to start()
.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 elements in the
given poolService
unit
- 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 poolService
IllegalArgumentException
- if one of the following holds:poolService == null || timeInterval <= 0 || unit == null || samples <= 0
public void start()
start
in interface ThreadedPoolReducer
protected void samplePool()
protected int calculateReduction()
protected void afterReduce(int reduction, int reduced, Throwable thrown)
reduction
- the intended reductionreduced
- the number of objects removed/destroyed from the poolthrown
- a thrown exception if any (a RuntimeException or an Error)public Thread.State getState()
getState
in interface ThreadedPoolReducer
public void terminate()
terminate
in interface ThreadedPoolReducer
Copyright © 2013-2014 Simeon Malchev. All Rights Reserved.