cancel()%uA0方法是用来终止此计时器,丢弃所有当前已安排的任务。
声明
以下是java.util.Timer.cancel()方法的声明。
public void cancel()
参数
-
NA
返回值
NA
异常
-
NA
例子
下面的例子显示java.util.Timer.cancel()方法的使用
package com.yiibai 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(), 100) // terminating the timer System.out.println("cancelling timer") timer.cancel() } // this method performs the task public void run() { System.out.println("working on") } }
现在编译和运行上面的代码示例,将产生以下结果。
cancelling timer
working on