Package com.pervasivecode.utils.time.api
Interface PeriodicRunner
-
- All Known Implementing Classes:
FakePeriodicRunner
,SimplePeriodicRunner
public interface PeriodicRunner
An object that can run a single Runnable task repeatedly at a steady rate. Callers can optionally stop (and then optionally re-start) the Runnable task.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
setPeriodicTask(Runnable task)
Specify the task that this PeriodicRunner should run periodically.void
start()
Start calling the specified Runnable task periodically.void
stop()
Stop calling the specified Runnable task periodically.
-
-
-
Method Detail
-
setPeriodicTask
void setPeriodicTask(Runnable task)
Specify the task that this PeriodicRunner should run periodically. The specified task will not be run until after thestart()
method has been called.- Parameters:
task
- The task to run periodically.- Throws:
IllegalStateException
- if a task has already been provided and has been started, but not stopped yet. To avoid this, stop the other task before calling this method.
-
start
void start()
Start calling the specified Runnable task periodically.- Throws:
IllegalStateException
- if no task has been provided, or if the task has already been started.
-
stop
void stop()
Stop calling the specified Runnable task periodically.- Throws:
IllegalStateException
- if no task has been provided, or has been provided but has not been started.
-
-