Interface TaskScheduler


public interface TaskScheduler
A task scheduler based on a ScheduledExecutorService, scheduled at a fixed rate, using a daemon thread by default. A TaskScheduler can be stopped and restarted.
 
 TaskScheduler scheduler = TaskScheduler.builder(() -> System.out.println("Running wild..."))
     .interval(2)
     .timeUnit(TimeUnit.SECONDS)
     .build();

 scheduler.start();
 ...
 scheduler.interval().set(1);//task restarted using the new interval
 ...
 scheduler.stop();
 
 
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    A builder for TaskScheduler
  • Method Summary

    Modifier and Type
    Method
    Description
     
    Controls the task interval and when set, in case this scheduler was running, re-schedules the task.
    boolean
     
    Starts this TaskScheduler, if it is running it is restarted, using the initial delay specified during construction.
    void
    Stops this TaskScheduler, if it is not running calling this method has no effect.
     
  • Method Details

    • interval

      Value<Integer> interval()
      Controls the task interval and when set, in case this scheduler was running, re-schedules the task. If the scheduler was stopped it will remain so, the new interval coming into effect on next start.
      Returns:
      the Value controlling the interval
    • timeUnit

      TimeUnit timeUnit()
      Returns:
      the time unit
    • start

      TaskScheduler start()
      Starts this TaskScheduler, if it is running it is restarted, using the initial delay specified during construction.
      Returns:
      this TaskScheduler instance
    • stop

      void stop()
      Stops this TaskScheduler, if it is not running calling this method has no effect.
    • running

      boolean running()
      Returns:
      true if this TaskScheduler is running
    • builder

      static TaskScheduler.Builder builder(Runnable task)
      Parameters:
      task - the task to run
      Returns:
      a new TaskScheduler.Builder instance.