timer cancel_Java Timer cancel()方法与示例
timer cancel
计时器类cancel()方法 (Timer Class cancel() method)
cancel() method is available in java.util package.
cancel()方法在java.util包中可用。
cancel() method is used to cancel this Timer and discard any task scheduled currently.
cancel()方法用于取消此Timer并丢弃当前调度的任何任务。
cancel() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
cancel()方法是一种非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
cancel() method does not throw an exception at the time of canceling timer.
cancel()方法在取消计时器时不会引发异常。
Syntax:
句法:
public void cancel();
Parameter(s):
参数:
It does not accept any parameter.
它不接受任何参数。
Return value:
返回值:
The return type of the method is void, it returns nothing.
该方法的返回类型为void ,不返回任何内容。
Example:
例:
// Java program to demonstrate the example
// of void cancel() method
// of Timer
import java.util.*;
class CancelTimer extends TimerTask {// Task defined in this method
public void run() {System.out.println("In Stock...Stop Working");
}
}
public class CancelOfTimer {public static void main(String[] args) {// Instantaites a TimerTask and
// Timer object
TimerTask task = new CancelTimer();
Timer tmr = new Timer();
// By using scheduleAtFixedRate() method isto
// schedule the task at a constant rate in a
// repeated manner
tmr.scheduleAtFixedRate(task, new Date(), 330);
// By using cancel() method is to
// cancel this timer and stop
// the scheduled task
System.out.println("tmr.cancel(): " + "Cancelled");
tmr.cancel();
}
}
Output
输出量
tmr.cancel(): Cancelled
In Stock...Stop Working
翻译自: https://www.includehelp.com/java/timer-cancel-method-with-example.aspx
timer cancel
timer cancel_Java Timer cancel()方法与示例相关推荐
- java cancel_Java RunnableFuture.cancel方法代码示例
import java.util.concurrent.RunnableFuture; //导入方法依赖的package包/类 @Test public void testSnapshotAsyncC ...
- timer purge_Java Timer purge()方法与示例
timer purge 计时器类purge()方法 (Timer Class purge() method) purge() method is available in java.util pack ...
- java中timer类包_Java~util包中Timer的使用, 演示cancel方法 和 对比schedule和scheduleAtFixedRate方法...
Timer Timer类的主要作用就是设置计划任务,但封装任务的类却是TimerTask类 执行计划任务的代码要放人TimerTask的子类中,因为TimerTask是一个抽象类.而且要重写其run方 ...
- python 计时方法_Python计时器类| cancel()方法与示例
python 计时方法 Python Timer.cancel()方法 (Python Timer.cancel() Method) cancel() is an inbuilt method of ...
- boost::timer模块timer、job_timer和progress_display示例程序
boost::timer模块timer.job_timer和progress_display示例程序 实现功能 C++实现代码 实现功能 boost::timer模块timer.job_timer和p ...
- python fonttool_Python wx.Font方法代码示例
本文整理汇总了Python中wx.Font方法的典型用法代码示例.如果您正苦于以下问题:Python wx.Font方法的具体用法?Python wx.Font怎么用?Python wx.Font使用 ...
- timer.schedule —— timer定时器的用法
Java.util.Timer定时器,实际上是个线程,定时调度所拥有的TimerTasks. 一个TimerTask实际上就是一个拥有run方法的类,需要定时执行的代码放到run方法体内,TimerT ...
- Java中的Timer和Timer Task详解
Java Timer&TimerTask原理分析 如果你使用Java语言进行开发,对于定时执行任务这样的需求,自然而然会想到使用Timer和TimerTask完成任务,我最近就使用 Timer ...
- 【Android 异步操作】Timer 定时器 ( Timer 与 TimerTask 基本使用 | Timer 定时器常用用法 | Timer 源码分析 )
文章目录 一.Timer 定时器基本使用 二.Timer 定时器常用用法 三.Timer 源码分析 四.Timer 部分源码注释 五.源码及资源下载 参考文档 : Timer 定时器 API 文档 T ...
最新文章
- 关于Silverlight中多项目共享DLL文件的讨论
- XAF-Domain Components 技术 使用接口来定义ORM业务对象
- java的单例设计模式
- jQuery仿淘宝商城天猫鼠标移动过去,透明度降低
- firefox英文网页乱码解决方法
- python文本处理第三方库是什么_python第三方库网站
- 休眠:保存vs持久并保存或更新
- asp.net尚未在web服务器上注册_最新版Web服务器项目详解 00 项目概述
- Java计基础---常用类之StringBuilder类--String、StringBuilder和StringBuffer 的区别
- 性能测试用例(转载)
- 数论基础之组合数计数问题
- nero免费中文版内含注册激活码获取器
- Http请求URL长度限制
- linux脚本解密,shell脚本加密与解密
- 新浪微博应用开发者协议真坑爹啊!
- SuperMap系列——GIS数据之地图瓦片
- 云服务器怎么存文件大小,云服务器怎么存文件大小
- 【计算社会科学01】为何病菌屡屡将人类推向死神?人类该如何应对
- matlab使用pcode加密
- 学习笔记:Oracle函数大全