Timer Class

Used to schedule tasks for future execution in a background thread. Tasks may be scheduled for one-time execution, or for repeated execution at regular intervals. Unlike the java.util.Timer class, this implementation does not silently cancel tasks if a task encounters an exception.

Constructors

Timer( )

Public Methods

schedule( Runnable task, long delay ) returns void
Schedules the specified task for execution after the specified delay.
task task to be scheduled.
delaydelay in milliseconds before task is to be executed.
schedule( Runnable task, java.util.Date time ) returns void
Schedules the specified task for execution at the specified time. If the time is in the past, the task is scheduled for immediate execution.
tasktask to be scheduled.
timetime at which task is to be executed.
scheduleAtFixedRate( Runnable task, java.util.Date firstTime, long period ) returns void
Schedules the specified task for repeated fixed-rate execution, beginning at the specified time. Subsequent executions take place at regular intervals, separated by the specified period.
taskTask to be scheduled.
firstTimeFirst time at which task is to be executed.
periodTime in milliseconds between successive task executions.
scheduleAtFixedRate( Runnable task, long delay, long period ) returns void
Schedules the specified task for repeated fixed-rate execution, beginning at the specified time. Subsequent executions take place at regular intervals, separated by the specified period.
taskTask to be scheduled.
delaydelay in milliseconds before task is to be executed.
periodTime in milliseconds between successive task executions.
cancel( ) returns void
Used to shutdown the current timer task
initialized( ) returns boolean
Returns true if the time task has been initialized

Static Methods

setInterval( Callback callback, long interval ) returns Timer
Used to repeatedly call a given function/callback, with a fixed time delay between each call. Example:
    setInterval(()->{
        System.out.println(new java.util.Date());
    }, 1000);    
callback
intervalTime in milliseconds between successive calls to the callback.
setTimeout( Callback callback, long delay ) returns Timer
Used to call a given function/callback after a delay. Example:
    long startTime = System.currentTimeMillis();
    setTimeout(()->{
        System.out.println(System.currentTimeMillis()-startTime);
    }, 1000);    
callback
delayDelay in milliseconds before the callback is called.

Public Classes