Timer Task 的简单范例(相当触发器,转自Sun)
==============================================
Date timeToRun =
new Date(System.currentTimeMillis()+
numberOfMillisecondsInTheFuture);
Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
// Task here
}
}, timeToRun);
============================================
Scheduling a Timer Task to Run Repeatedly
=============================================
// delay for 5 sec.
int delay = 5000;
// repeat every sec.
int period = 1000;
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
// Task here
}
}, delay, period);
Tags:
作者:佚名评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论