java.util.Timer.purge() 方法
描述
purge() 方法用于从该计时器的任务队列中删除所有已取消的任务。
声明
以下是 java.util.Timer.purge() 方法的声明。
public int purge()
参数
NA
返回值
方法调用返回从队列中移除的任务数。
异常
NA
示例
下面的例子展示了 java.util.Timer.purge() 的用法。
package com.tutorialspoint;
import java.util.*;
public class TimerDemo {
public static void main(String[] args) {
// creating timer task, timer
TimerTask tasknew = new TimerCancel();
Timer timer = new Timer();
// scheduling the task
timer.scheduleAtFixedRate(tasknew, new Date(), 10);
// cancel task
timer.cancel();
// purging the timer
System.out.println("purge value :"+timer.purge());
}
// this method performs the task
public void run() {
System.out.println("working on");
}
}
让我们编译并运行上面的程序,这将产生以下结果.
working on purge value :0

