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 Summary

    Modifier and Type
    Method
    Description
    int
    Returns the number of tasks that are currently scheduled for execution by the timer.
    int
    Returns the ID of this timer.
    schedule(long delayInMillis, Runnable task)
    Schedules the task to be executed in delayInMillis on this timer's default Executor.
    schedule(long delayInMillis, Runnable task, Executor executor)
    Schedules the task to be executed in delayInMillis on given executor.
    void
    Shuts down this timer.
  • 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

      TimerTask schedule(long delayInMillis, Runnable task)
      Schedules the task to be executed in delayInMillis on this timer's default Executor.

      Equivalent to schedule(delayInMillis, task, null).

    • schedule

      TimerTask schedule(long delayInMillis, Runnable task, Executor executor)
      Schedules the task to be executed in delayInMillis on given executor. If executor is null, 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

      void shutdown() throws InterruptedException
      Shuts down this timer. Returns after all internal resources of this timer are shut down.
      Throws:
      InterruptedException