Interface Timer
- All Known Implementing Classes:
ThreadTimer
public interface Timer
Timer allows scheduling tasks for execution in the future. Tasks are always executed
on a well-defined
Executor. Timer implementations must have a default executor
for tasks scheduled using schedule(long, Runnable). Tasks scheduled using
schedule(long, Runnable, Executor) are executed on the given executor.-
Method Details
-
getId
int getId()Returns the ID of this timer. Timer IDs are guaranteed to be unique.- Returns:
- the ID of this timer
-
schedule
Schedules thetaskto be executed indelayInMillison this timer's defaultExecutor.Equivalent to
schedule(delayInMillis, task, null). -
schedule
Schedules thetaskto be executed indelayInMillison givenexecutor. Ifexecutorisnull, this timer's default executor is used. -
countScheduledTasks
int countScheduledTasks()Returns the number of tasks that are currently scheduled for execution by the timer. Finished tasks and tasks that are already running are not included.- Returns:
- the number of currently scheduled tasks
-
shutdown
Shuts down this timer. Returns after all internal resources of this timer are shut down.- Throws:
InterruptedException
-