Package wt.jmx.core

Class PeriodicTaskSupport

java.lang.Object
wt.jmx.core.BackgroundTaskSupport
wt.jmx.core.PeriodicTaskSupport

public abstract class PeriodicTaskSupport extends BackgroundTaskSupport
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

    Constructors
    Constructor
    Description
    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

    Modifier and Type
    Method
    Description
    protected abstract Runnable
    This method must be overridden to return the Runnable task for periodic execution by this class.
    int
    Delay of first task execution in seconds.
    int
    Returns time interval at which task is executed (in seconds).
    boolean
    Whether this instance will run its task at a fixed delay or a fixed rate; by default this class uses a fixed rate.
    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.
    void
    Called by start() and by setTaskIntervalSeconds() when necessary.
    void
    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 Details

    • PeriodicTaskSupport

      public PeriodicTaskSupport()
      Default constructor

      Supported API: true
    • PeriodicTaskSupport

      public PeriodicTaskSupport(int taskIntervalSeconds)
      Constructor; arguments set corresponding properties

      Supported API: true
    • PeriodicTaskSupport

      public PeriodicTaskSupport(String timerThreadNamePrefix)
      Constructor; arguments set corresponding properties

      Supported API: true
    • PeriodicTaskSupport

      public PeriodicTaskSupport(String timerThreadNamePrefix, int taskIntervalSeconds)
      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

      public PeriodicTaskSupport(String timerThreadNamePrefix, boolean daemon)
      Constructor; arguments set corresponding properties

      Supported API: true
    • PeriodicTaskSupport

      public PeriodicTaskSupport(String timerThreadNamePrefix, boolean daemon, int taskIntervalSeconds)
      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

      protected abstract Runnable 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:
      createTask in class BackgroundTaskSupport
    • 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:
      startTask in class BackgroundTaskSupport
    • 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:
      stopTask in class BackgroundTaskSupport