Timer TimerTask学习

[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]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值