Class PeriodicalScheduledTask

  • All Implemented Interfaces:
    java.lang.Runnable

    public class PeriodicalScheduledTask
    extends java.lang.Object
    implements java.lang.Runnable
    This class can be used when we have a periodical task, but we don't want to execute the task only if there's something to do For instance, we would like to periodically serialize a state of a cache to disk, but only when cache has been changed. Initialization:
     PeriodicalScheduledTask myTask = new PeriodicalScheduledTask("Task", ()->storeData());
     executorServices.getNormalExecutorService().scheduleWithFixedDelay(myTask, delay, delay, TimeUnit.SECONDS);
     
    Schedule:
       myTask.schedule();
     
    Since:
    2018.2
    • Constructor Summary

      Constructors 
      Constructor Description
      PeriodicalScheduledTask​(java.lang.String actionName, java.lang.Runnable innerAction)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean isPending()  
      void run()  
      void schedule()
      Schedules task for execution
      • Methods inherited from class java.lang.Object

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

      • PeriodicalScheduledTask

        public PeriodicalScheduledTask​(@NotNull
                                       java.lang.String actionName,
                                       @NotNull
                                       java.lang.Runnable innerAction)
    • Method Detail

      • schedule

        public void schedule()
        Schedules task for execution
      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable
      • isPending

        public boolean isPending()