Package java.util

Class TimerTask

  • All Implemented Interfaces:
    Runnable

    public abstract class TimerTask
    extends Object
    implements Runnable
    A task to be scheduled in a Timer. Is it assumed that each TimerTask is at most once in a Timer and is used in at most one scheduling call.
    • Constructor Detail

      • TimerTask

        protected TimerTask()
    • Method Detail

      • run

        public abstract void run()
        Inherited from Runnable
        Specified by:
        run in interface Runnable
      • cancel

        public boolean cancel()
        Cancels this task and guarantees that this task will never run again.

        If this task is currently running, the current run() will be allowed to complete. cancel() can be called more than once and it has no effect after the first call.

        Returns true iff. at least one run of the task was cancelled. Note that if the given task wasn’t scheduled, there’s nothing to cancel (by definition) so this method must return false in that case.

      • scheduledExecutionTime

        public long scheduledExecutionTime()
        Returns the time at which the most recent execution of this task was scheduled to occur.

        Because task execution can occur later than scheduled this method can be used within the run() method to calculate the difference between the scheduled and actual execution time.

        The return value is undefined for tasks that have never been run.