Class ReschedulingOperation


  • public abstract class ReschedulingOperation
    extends java.lang.Object
    Abstract implementation for more complicated recurring behavior. Unlike submitting a task to SubmitterScheduler.scheduleWithFixedDelay(Runnable, long, long), this can provide the ability to only have the task scheduled if there is work to do. In addition it provides the ability to change the frequency of execution without needing to remove and re-add the task.

    This task will only schedule or reschedule itself if it has been notified there is work to do. It is assumed that after execution all work is complete. If there is additional work to perform, then the task should invoke signalToRun() before it completes to ensure that it is rescheduled at the current set delay. Because of that behavior there is no way to remove this task from the scheduler, instead you must just ensure that signalToRun() is not invoked to prevent the task from rescheduling itself.

    An additional advantage to using this over scheduling a recurring task is that you don't have to worry about removing the task before garbage collection occurs (ie no cleanup, just stop invoking signalToRun()).

    Since:
    4.9.0
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean isActive()
      Check to see if this operation is either currently running, or scheduled to run.
      void setScheduleDelay​(long scheduleDelay)
      Adjusts the delay at which this task is scheduled or rescheduled.
      void signalToRun()
      Invoke to indicate that this operation has stuff to do.
      void signalToRunImmediately​(boolean runOnCallingThreadIfPossible)
      Similar to signalToRun() except that any configured schedule / delay will be ignored and instead the task will try to run ASAP.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • isActive

        public boolean isActive()
        Check to see if this operation is either currently running, or scheduled to run.
        Returns:
        true means this operation still has things to do
      • setScheduleDelay

        public void setScheduleDelay​(long scheduleDelay)
        Adjusts the delay at which this task is scheduled or rescheduled. This can be invoked during run() to change how long till it executes next.
        Parameters:
        scheduleDelay - Delay in milliseconds to schedule operation out on, can not be negative
      • signalToRunImmediately

        public void signalToRunImmediately​(boolean runOnCallingThreadIfPossible)
        Similar to signalToRun() except that any configured schedule / delay will be ignored and instead the task will try to run ASAP.
        Parameters:
        runOnCallingThreadIfPossible - true to run the task on the invoking thread if possible
      • signalToRun

        public void signalToRun()
        Invoke to indicate that this operation has stuff to do. If necessary the task will be scheduled for execution. If the task is already running then it will ensure the task re-executes itself when done (at the set delay). This re-execution can help ensure that any thread state changes can be witnessed on the next execution.

        If you want to signal the task to run immediately (ignore the schedule delay) please see signalToRunImmediately(boolean).