Package wt.jmx.core
Class PeriodicTaskSupport
java.lang.Object
wt.jmx.core.BackgroundTaskSupport
wt.jmx.core.PeriodicTaskSupport
This abstract class takes care of most of the drudgery of properly setting
up a task for repeated execution on a specific, periodic interval. This
includes support for start() and stop() lifecycle operations as well as
changes to the interval frequency.
Note that though this class defaults to daemon threads unless otherwise
specified by the caller. Also note that the default implementation of
createExecutor() returns a SharedScheduledExecutor as
the backing executor, which implies some limitations as compared to normal
ScheduledExecutorService implementations.
Supported API: true
Extendable: true
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor
Supported API: truePeriodicTaskSupport(boolean daemon) Constructor; arguments set corresponding properties
Supported API: truePeriodicTaskSupport(boolean daemon, int taskIntervalSeconds) Constructor; arguments set corresponding properties
Supported API: truePeriodicTaskSupport(int taskIntervalSeconds) Constructor; arguments set corresponding properties
Supported API: truePeriodicTaskSupport(String timerThreadNamePrefix) Constructor; arguments set corresponding properties
Supported API: truePeriodicTaskSupport(String timerThreadNamePrefix, boolean daemon) Constructor; arguments set corresponding properties
Supported API: truePeriodicTaskSupport(String timerThreadNamePrefix, boolean daemon, int taskIntervalSeconds) Constructor; arguments set corresponding properties
Supported API: truePeriodicTaskSupport(String timerThreadNamePrefix, boolean daemon, int taskIntervalSeconds, int firstExecutionDelaySeconds) Constructor; arguments set corresponding properties
Supported API: truePeriodicTaskSupport(String timerThreadNamePrefix, boolean daemon, int taskIntervalSeconds, int firstExecutionDelaySeconds, boolean fixedDelay) Constructor; arguments set corresponding properties
Supported API: truePeriodicTaskSupport(String timerThreadNamePrefix, int taskIntervalSeconds) Constructor; arguments set corresponding properties
Supported API: true -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract RunnableThis method must be overridden to return the Runnable task for periodic execution by this class.intDelay of first task execution in seconds.intReturns time interval at which task is executed (in seconds).booleanWhether this instance will run its task at a fixed delay or a fixed rate; by default this class uses a fixed rate.voidsetFirstExecutionDelaySeconds(int firstExecutionDelaySeconds) Delay of first task execution in seconds.voidsetTaskIntervalSeconds(int taskIntervalSeconds) Sets time interval at which task is executed (in seconds); task execution is disabled if this is non-positive.voidCalled by start() and by setTaskIntervalSeconds() when necessary.voidstopTask()Called by stop() and by setTaskIntervalSeconds() when necessary.Methods inherited from class wt.jmx.core.BackgroundTaskSupport
createExecutor, getTimerThreadNamePrefix, isDaemon, isStarted, shutdownExecutor, start, stop
-
Constructor Details
-
PeriodicTaskSupport
public PeriodicTaskSupport()Default constructor
Supported API: true -
PeriodicTaskSupport
public PeriodicTaskSupport(int taskIntervalSeconds) Constructor; arguments set corresponding properties
Supported API: true -
PeriodicTaskSupport
Constructor; arguments set corresponding properties
Supported API: true -
PeriodicTaskSupport
Constructor; arguments set corresponding properties
Supported API: true -
PeriodicTaskSupport
public PeriodicTaskSupport(boolean daemon) Constructor; arguments set corresponding properties
Supported API: true -
PeriodicTaskSupport
public PeriodicTaskSupport(boolean daemon, int taskIntervalSeconds) Constructor; arguments set corresponding properties
Supported API: true -
PeriodicTaskSupport
Constructor; arguments set corresponding properties
Supported API: true -
PeriodicTaskSupport
Constructor; arguments set corresponding properties
Supported API: true -
PeriodicTaskSupport
public PeriodicTaskSupport(String timerThreadNamePrefix, boolean daemon, int taskIntervalSeconds, int firstExecutionDelaySeconds) Constructor; arguments set corresponding properties
Supported API: true -
PeriodicTaskSupport
public PeriodicTaskSupport(String timerThreadNamePrefix, boolean daemon, int taskIntervalSeconds, int firstExecutionDelaySeconds, boolean fixedDelay) Constructor; arguments set corresponding properties
Supported API: true
-
-
Method Details
-
createTask
This method must be overridden to return the Runnable task for periodic execution by this class. Note that besides on initial startup of the periodic task this method is called whenever the task interval is changed, thus replacing the task instance with whatever this method returns.
Supported API: true- Specified by:
createTaskin classBackgroundTaskSupport
-
getTaskIntervalSeconds
public int getTaskIntervalSeconds()Returns time interval at which task is executed (in seconds).
Supported API: true -
setTaskIntervalSeconds
public void setTaskIntervalSeconds(int taskIntervalSeconds) Sets time interval at which task is executed (in seconds); task execution is disabled if this is non-positive.
Supported API: true -
getFirstExecutionDelaySeconds
public int getFirstExecutionDelaySeconds()Delay of first task execution in seconds. A negative value implies that the taskIntervalSeconds will be used instead.
Supported API: true -
setFirstExecutionDelaySeconds
public void setFirstExecutionDelaySeconds(int firstExecutionDelaySeconds) Delay of first task execution in seconds. A negative value implies that the taskIntervalSeconds will be used instead.Note that calling this method has no effect on this instance while it is in a started/running state, but will have an effect the next time the task is restarted (including upon a call to setTaskIntervalSeconds()).
Supported API: true -
isFixedDelay
public boolean isFixedDelay()Whether this instance will run its task at a fixed delay or a fixed rate; by default this class uses a fixed rate.
Supported API: true -
startTask
public void startTask()Called by start() and by setTaskIntervalSeconds() when necessary. Should only need to be called directly when something else causes a need to temporarily pause and restart the task. This is more efficient than calling stop and then start.Warning: This routine is a no-op when this object is not started (see start() and isStarted()).
Supported API: true- Specified by:
startTaskin classBackgroundTaskSupport
-
stopTask
public void stopTask()Called by stop() and by setTaskIntervalSeconds() when necessary. Should only need to be called directly when something else causes a need to temporarily pause and restart the task. This is more efficient than calling stop and then start.
Supported API: true- Specified by:
stopTaskin classBackgroundTaskSupport
-