📅  最后修改于: 2020-11-14 06:25:21             🧑  作者: Mango
java.util.Timer类为线程提供了便利,可用于安排任务以供将来在后台线程中执行。
此类是线程安全的,即,多个线程可以共享一个Timer对象,而无需外部同步。
此类计划任务一次执行或定期执行重复执行。
所有构造函数都启动一个计时器线程。
以下是java.util.Timer类的声明-
public class Timer
extends Object
Sr.No. | Constructor & Description |
---|---|
1 |
Timer() This constructor creates a new timer. |
2 |
Timer(boolean isDaemon) This constructor creates a new timer whose associated thread may be specified to run as a daemon. |
3 |
Timer(String name) This constructor creates a new timer whose associated thread has the specified name. |
4 |
Timer(String name, boolean isDaemon) This constructor creates a new timer whose associated thread has the specified name, and may be specified to run as a daemon. |
Sr.No. | Method & Description |
---|---|
1 | void cancel()
This method terminates this timer, discarding any currently scheduled tasks. |
2 | int purge()
This method removes all cancelled tasks from this timer’s task queue. |
3 | void schedule(TimerTask task, Date time)
This method schedules the specified task for execution at the specified time. |
4 | void schedule(TimerTask task, Date firstTime, long period)
This method schedules the specified task for repeated fixed-delay execution, beginning at the specified time. |
5 | void schedule(TimerTask task, long delay)
This method schedules the specified task for execution after the specified delay. |
6 | void schedule(TimerTask task, long delay, long period)
This method schedules the specified task for repeated fixed-delay execution, beginning after the specified delay. |
7 | void scheduleAtFixedRate(TimerTask task, Date firstTime, long period)
This method schedules the specified task for repeated fixed-rate execution, beginning at the specified time. |
8 | void scheduleAtFixedRate(TimerTask task, long delay, long period)
This method Schedules the specified task for repeated fixed-rate execution, beginning after the specified delay. |
此类从以下类继承方法-