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 -
Method Summary
Modifier and TypeMethodDescriptionstatic TaskScheduler.Builder
interval()
Controls the task interval and when set, in case this scheduler was running, re-schedules the task.boolean
running()
start()
Starts this TaskScheduler, if it is running it is restarted, using the initial delay specified during construction.void
stop()
Stops this TaskScheduler, if it is not running calling this method has no effect.timeUnit()
-
Method Details
-
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
- Parameters:
task
- the task to run- Returns:
- a new
TaskScheduler.Builder
instance.
-