Class ProtectedTimerTask

  • All Implemented Interfaces:
    java.lang.Runnable

    public abstract class ProtectedTimerTask
    extends java.util.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.

    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract void execute()  
      void run()  
      void stopTimer()
      Stop the timer.
      • Methods inherited from class java.util.TimerTask

        cancel, scheduledExecutionTime
      • Methods inherited from class java.lang.Object

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

      • execute

        public abstract void execute()
      • run

        public final void run()
        Specified by:
        run in interface java.lang.Runnable
        Specified by:
        run in class java.util.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.