[size=medium]Timer TimerTask类
位于java.util包下
TimerTask public abstract class TimerTask extends Object implements Runnable
抽象类,且ctors是protected,故必须继承后调用它的ctors.
类的描述是:The TimerTask class represents a task to run at a specified time. The task may be run once or repeatedly.
TimerTask类代表一个在指定时间运行的类,任务可以执行一次或重复执行...
可以这样理解:Timer是个定时器,而TimerTask就是给Timer使用的任务.
Timer类内的方法列表:
void:有4个schedule的重写方法,(约定执行任务的间隔)
void:2个scheduleAtFixedRate的重写方法,(以稳定的间隔或速率执行任务)
int:1个purge方法 (Removes all canceled tasks from the task queue.)return:the number of canceled tasks that were removed from the task queue.
void:一个cancel方法(取消任务执行)Cancels the Timer and all scheduled tasks.
TimerTask类内的方法列表:
1个cancel方法:boolean Cancels the TimerTask and removes it from the Timer's queue.(返回boolean值,可以做为判断是否停止执行的标准)
1个run方法,:void The task to run should be specified in the implementation of the run() method.(将要执行的任务放到这里)
1个scheduleExecutionTime:long Returns the scheduled execution time.
[/size]
实例参考:[url]http://nmj1987.iteye.com/blog/343748[/url]
位于java.util包下
TimerTask public abstract class TimerTask extends Object implements Runnable
抽象类,且ctors是protected,故必须继承后调用它的ctors.
类的描述是:The TimerTask class represents a task to run at a specified time. The task may be run once or repeatedly.
TimerTask类代表一个在指定时间运行的类,任务可以执行一次或重复执行...
可以这样理解:Timer是个定时器,而TimerTask就是给Timer使用的任务.
Timer类内的方法列表:
void:有4个schedule的重写方法,(约定执行任务的间隔)
void:2个scheduleAtFixedRate的重写方法,(以稳定的间隔或速率执行任务)
int:1个purge方法 (Removes all canceled tasks from the task queue.)return:the number of canceled tasks that were removed from the task queue.
void:一个cancel方法(取消任务执行)Cancels the Timer and all scheduled tasks.
TimerTask类内的方法列表:
1个cancel方法:boolean Cancels the TimerTask and removes it from the Timer's queue.(返回boolean值,可以做为判断是否停止执行的标准)
1个run方法,:void The task to run should be specified in the implementation of the run() method.(将要执行的任务放到这里)
1个scheduleExecutionTime:long Returns the scheduled execution time.
[/size]
实例参考:[url]http://nmj1987.iteye.com/blog/343748[/url]