Java Timer class

The Java Timer class provides a facility for the thread to schedule tasks for future execution in a background thread. This class is thread-safe that means multiple class can share a single Timer object without using the external synchronization.

Java Timer Methods

SNMethodDescription
1cancel()It is used to stop the timer and remove the currently scheduled task.
2Purge()It is used to cancel the tasks present in TimerTask Chain.
3scheduleAtFixedRate(TimerTask task, Date firstTime, long period)It is used to schedules the specified task for repeated fixed-rate execution, beginning at the specified time.
4scheduleAtFixedRate(TimerTask task, long delay, long period)It is used to schedules the specified task for repeated fixed-rate execution, beginning after the specified delay.
5schedule(TimerTask task, Date firstTime, long period)It is used to schedules the specified task for repeated fixed-delay execution, beginning at the specified time.
6schedule(TimerTask task, Date time)It is used to schedules the specified task for execution at the specified time.