描述
該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