|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectwt.jmx.core.PeriodicTaskSupport
public abstract class 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 | |
|---|---|
PeriodicTaskSupport()
Default constructor Supported API: true |
|
PeriodicTaskSupport(boolean daemon)
Constructor; arguments set corresponding properties Supported API: true |
|
PeriodicTaskSupport(boolean daemon,
int taskIntervalSeconds)
Constructor; arguments set corresponding properties Supported API: true |
|
PeriodicTaskSupport(int taskIntervalSeconds)
Constructor; arguments set corresponding properties Supported API: true |
|
PeriodicTaskSupport(String timerThreadNamePrefix)
Constructor; arguments set corresponding properties Supported API: true |
|
PeriodicTaskSupport(String timerThreadNamePrefix,
boolean daemon)
Constructor; arguments set corresponding properties Supported API: true |
|
PeriodicTaskSupport(String timerThreadNamePrefix,
boolean daemon,
int taskIntervalSeconds)
Constructor; arguments set corresponding properties Supported API: true |
|
PeriodicTaskSupport(String timerThreadNamePrefix,
boolean daemon,
int taskIntervalSeconds,
int firstExecutionDelaySeconds)
Constructor; arguments set corresponding properties Supported API: true |
|
PeriodicTaskSupport(String timerThreadNamePrefix,
boolean daemon,
int taskIntervalSeconds,
int firstExecutionDelaySeconds,
boolean fixedDelay)
Constructor; arguments set corresponding properties Supported API: true |
|
PeriodicTaskSupport(String timerThreadNamePrefix,
int taskIntervalSeconds)
Constructor; arguments set corresponding properties Supported API: true |
|
| Method Summary | |
|---|---|
protected ScheduledExecutorService |
createExecutor(String timerThreadNamePrefix,
boolean daemon)
Provides ScheduledExecutorService instance used for execution. |
protected abstract Runnable |
createTask()
This method must be overriden to return the Runnable task for periodic execution by this class. |
int |
getFirstExecutionDelaySeconds()
Delay of first task execution in seconds. |
int |
getTaskIntervalSeconds()
Returns time interval at which task is executed (in seconds). |
String |
getTimerThreadNamePrefix()
The prefix name given to all threads associated with the underlying time. |
boolean |
isDaemon()
Whether the daemon or non-daemon threads should be used. |
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. |
boolean |
isStarted()
Returns whether this instance is currently running, i.e start() has been called more recently than stop(). |
boolean |
isTaskStarted()
Whether task itself is currently started. |
void |
setFirstExecutionDelaySeconds(int firstExecutionDelaySeconds)
Delay of first task execution in seconds. |
void |
setTaskIntervalSeconds(int taskIntervalSeconds)
Sets time interval at which task is executed (in seconds); task execution is disabled if this is non-positive. |
protected void |
shutdownExecutor(ScheduledExecutorService executor)
Shutdown the ScheduledExecutorService instance (that produced by createExecutor()) via executor.shutdown(). |
void |
start()
Start periodic background execution of task. |
void |
startTask()
Called by start() and by setTaskIntervalSeconds() when necessary. |
void |
stop()
Stop periodic background execution of task. |
void |
stopTask()
Called by stop() and by setTaskIntervalSeconds() when necessary. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public PeriodicTaskSupport()
public PeriodicTaskSupport(int taskIntervalSeconds)
public PeriodicTaskSupport(String timerThreadNamePrefix)
public PeriodicTaskSupport(String timerThreadNamePrefix,
int taskIntervalSeconds)
public PeriodicTaskSupport(boolean daemon)
public PeriodicTaskSupport(boolean daemon,
int taskIntervalSeconds)
public PeriodicTaskSupport(String timerThreadNamePrefix,
boolean daemon)
public PeriodicTaskSupport(String timerThreadNamePrefix,
boolean daemon,
int taskIntervalSeconds)
public PeriodicTaskSupport(String timerThreadNamePrefix,
boolean daemon,
int taskIntervalSeconds,
int firstExecutionDelaySeconds)
public PeriodicTaskSupport(String timerThreadNamePrefix,
boolean daemon,
int taskIntervalSeconds,
int firstExecutionDelaySeconds,
boolean fixedDelay)
| Method Detail |
|---|
protected abstract Runnable createTask()
public boolean isStarted()
public void start()
public void stop()
public int getTaskIntervalSeconds()
public void setTaskIntervalSeconds(int taskIntervalSeconds)
public int getFirstExecutionDelaySeconds()
public void setFirstExecutionDelaySeconds(int firstExecutionDelaySeconds)
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
public String getTimerThreadNamePrefix()
SharedScheduledExecutor to share
thread pools for all instances with the same prefix name and daemon flag.
A value of null here implies that a default prefix will be used in
SharedScheduledExecutor.
public boolean isDaemon()
public boolean isFixedDelay()
public boolean isTaskStarted()
public void startTask()
Warning: This routine is a no-op when this object is not started (see
start() and isStarted()).
Supported API: true
public void stopTask()
protected ScheduledExecutorService createExecutor(String timerThreadNamePrefix,
boolean daemon)
SharedScheduledExecutor and should almost
always suffice as is.
protected void shutdownExecutor(ScheduledExecutorService executor)
SharedScheduledExecutor
and should almost always suffice as is.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||