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()方法与示例相关推荐

  1. java cancel_Java RunnableFuture.cancel方法代码示例

    import java.util.concurrent.RunnableFuture; //导入方法依赖的package包/类 @Test public void testSnapshotAsyncC ...

  2. timer purge_Java Timer purge()方法与示例

    timer purge 计时器类purge()方法 (Timer Class purge() method) purge() method is available in java.util pack ...

  3. java中timer类包_Java~util包中Timer的使用, 演示cancel方法 和 对比schedule和scheduleAtFixedRate方法...

    Timer Timer类的主要作用就是设置计划任务,但封装任务的类却是TimerTask类 执行计划任务的代码要放人TimerTask的子类中,因为TimerTask是一个抽象类.而且要重写其run方 ...

  4. python 计时方法_Python计时器类| cancel()方法与示例

    python 计时方法 Python Timer.cancel()方法 (Python Timer.cancel() Method) cancel() is an inbuilt method of ...

  5. boost::timer模块timer、job_timer和progress_display示例程序

    boost::timer模块timer.job_timer和progress_display示例程序 实现功能 C++实现代码 实现功能 boost::timer模块timer.job_timer和p ...

  6. python fonttool_Python wx.Font方法代码示例

    本文整理汇总了Python中wx.Font方法的典型用法代码示例.如果您正苦于以下问题:Python wx.Font方法的具体用法?Python wx.Font怎么用?Python wx.Font使用 ...

  7. timer.schedule —— timer定时器的用法

    Java.util.Timer定时器,实际上是个线程,定时调度所拥有的TimerTasks. 一个TimerTask实际上就是一个拥有run方法的类,需要定时执行的代码放到run方法体内,TimerT ...

  8. Java中的Timer和Timer Task详解

    Java Timer&TimerTask原理分析 如果你使用Java语言进行开发,对于定时执行任务这样的需求,自然而然会想到使用Timer和TimerTask完成任务,我最近就使用 Timer ...

  9. 【Android 异步操作】Timer 定时器 ( Timer 与 TimerTask 基本使用 | Timer 定时器常用用法 | Timer 源码分析 )

    文章目录 一.Timer 定时器基本使用 二.Timer 定时器常用用法 三.Timer 源码分析 四.Timer 部分源码注释 五.源码及资源下载 参考文档 : Timer 定时器 API 文档 T ...

最新文章

  1. 关于Silverlight中多项目共享DLL文件的讨论
  2. XAF-Domain Components 技术 使用接口来定义ORM业务对象
  3. java的单例设计模式
  4. jQuery仿淘宝商城天猫鼠标移动过去,透明度降低
  5. firefox英文网页乱码解决方法
  6. python文本处理第三方库是什么_python第三方库网站
  7. 休眠:保存vs持久并保存或更新
  8. asp.net尚未在web服务器上注册_最新版Web服务器项目详解 00 项目概述
  9. Java计基础---常用类之StringBuilder类--String、StringBuilder和StringBuffer 的区别
  10. 性能测试用例(转载)
  11. 数论基础之组合数计数问题
  12. nero免费中文版内含注册激活码获取器
  13. Http请求URL长度限制
  14. linux脚本解密,shell脚本加密与解密
  15. 新浪微博应用开发者协议真坑爹啊!
  16. SuperMap系列——GIS数据之地图瓦片
  17. 云服务器怎么存文件大小,云服务器怎么存文件大小
  18. 【计算社会科学01】为何病菌屡屡将人类推向死神?人类该如何应对
  19. matlab使用pcode加密
  20. 学习笔记:Oracle函数大全

热门文章

  1. C语言——整型整除,浮点数整除
  2. GSoC 2022 Blender VSE: 第二、三周总结
  3. matlab中的strfind和findstr函数
  4. 基于高德SDK实现跑步时轨迹渐变功能
  5. 免费在线!!!多PDF合成一个PDF
  6. 5分钟成为车联网专家|智慧高速如何破局实现车联网最先商用落地
  7. 惊了!这才是真正的 Windows 摸鱼神器!!!
  8. 音视频技术学习总结入门
  9. 物联网协议之一:MQTT协议和kafka
  10. PyTorch开发者福音, OpenVINO整合PyTorch实现推理加速!