Class ProtectedTimerTask

java.lang.Object
java.util.TimerTask
jmri.jmrit.logixng.util.ProtectedTimerTask
All Implemented Interfaces:
Runnable

public abstract class ProtectedTimerTask extends TimerTask
A timer task that can be stopped, and there the stop method waits until the task is finished.

Note that this class does [u]not[/u] work for repeating timers. The class can be used for tasks that are scheduled over and over again, but only works for one shoot timer.

In other words, the class works for TimerUtil.schedule(@Nonnull TimerTask task, long delay) but not for TimerUtil.schedule(@Nonnull TimerTask task, long delay, long period). This is due to how the method TimerTask.cancel() works.

  • Constructor Details

  • Method Details

    • execute

      public abstract void execute()
    • run

      public final void run()
      Specified by:
      run in interface Runnable
      Specified by:
      run in class TimerTask
    • stopTimer

      public void stopTimer()
      Stop the timer. This method will not return until the timer task is cancelled and stopped. This code ensures that we don't return from this method until the timer task is cancelled and that it's not running any more.