- 浏览: 75561 次
- 性别:
- 来自: 厦门
文章分类
最新评论
-
覃永波:
引用[*][img][/img][url][/url]
java 读取txt,java读取大文件 -
bits00:
...
tcpdump网摘
如果要在程序中定时执行任务,可以使用java.util.Timer这个类实现。使用Timer类需要一个继承了
java.util.TimerTask的类。TimerTask是一个虚类,需要实现它的run方法,实际上是他implements了
Runnable接口,而把run方法留给子类实现。
下面是我的一个例子:
public void run() {
System. out .println( " 我在工作啦! " );
}
}
Timer类用schedule方法或者scheduleAtFixedRate方法启动定时执行,schedule重载了四个版本,scheduleAtFixedRate重载了两个。每个方法的实现都不同,下面是每个方法的说明:
schedule
public void schedule (TimerTask task, long delay)
task
- task to be scheduled.
delay
- delay in milliseconds before task is to be executed.
IllegalArgumentException
- if delay
is negative, or delay + System.currentTimeMillis()
is negative.
IllegalStateException
- if task was already scheduled or cancelled, or timer was cancelled.说明:该方法会在设定的延时后执行一次任务。
schedule
public void schedule (TimerTask task, Date time)
task
- task to be scheduled.
time
- time at which task is to be executed.
IllegalArgumentException
- if time.getTime()
is negative.
IllegalStateException
- if task was already scheduled or cancelled, timer was cancelled, or timer thread terminated.说明:该方法会在指定的时间点执行一次任务。
schedule
public void schedule (TimerTask task, long delay, long period)
In fixed-delay execution, each execution is scheduled relative to the actual execution time of the previous execution. If an execution is delayed for any reason (such as garbage collection or other background activity), subsequent executions will be delayed as well. In the long run, the frequency of execution will generally be slightly lower than the reciprocal of the specified period (assuming the system clock underlying Object.wait(long) is accurate).
Fixed-delay execution is appropriate for recurring activities that require "smoothness." In other words, it is appropriate for activities where it is more important to keep the frequency accurate in the short run than in the long run. This includes most animation tasks, such as blinking a cursor at regular intervals. It also includes tasks wherein regular activity is performed in response to human input, such as automatically repeating a character as long as a key is held down.
task
- task to be scheduled.
delay
- delay in milliseconds before task is to be executed.
period
- time in milliseconds between successive task executions.
IllegalArgumentException
- if delay
is negative, or delay + System.currentTimeMillis()
is negative.
IllegalStateException
- if task was already scheduled or cancelled, timer was cancelled, or timer thread terminated.说明:该方法会在指定的延时后执行任务,并且在设定的周期定时执行任务。
schedule
public void schedule (TimerTask task, Date firstTime, long period)
In fixed-delay execution, each execution is scheduled relative to the actual execution time of the previous execution. If an execution is delayed for any reason (such as garbage collection or other background activity), subsequent executions will be delayed as well. In the long run, the frequency of execution will generally be slightly lower than the reciprocal of the specified period (assuming the system clock underlying Object.wait(long) is accurate).
Fixed-delay execution is appropriate for recurring activities that require "smoothness." In other words, it is appropriate for activities where it is more important to keep the frequency accurate in the short run than in the long run. This includes most animation tasks, such as blinking a cursor at regular intervals. It also includes tasks wherein regular activity is performed in response to human input, such as automatically repeating a character as long as a key is held down.
task
- task to be scheduled.
firstTime
- First time at which task is to be executed.
period
- time in milliseconds between successive task executions.
IllegalArgumentException
- if time.getTime()
is negative.
IllegalStateException
- if task was already scheduled or cancelled, timer was cancelled, or timer thread terminated.说明:该方法会在指定的时间点执行任务,然后从该时间点开始,在设定的周期定时执行任务。特别的,如果设定的时间点在当前时间之前,任务会被马上执行,然后开始按照设定的周期定时执行任务。
scheduleAtFixedRate
public void scheduleAtFixedRate (TimerTask task, long delay, long period)
In fixed-rate execution, each execution is scheduled relative to the scheduled execution time of the initial execution. If an execution is delayed for any reason (such as garbage collection or other background activity), two or more executions will occur in rapid succession to "catch up." In the long run, the frequency of execution will be exactly the reciprocal of the specified period (assuming the system clock underlying Object.wait(long) is accurate).
Fixed-rate execution is appropriate for recurring activities that are sensitive to absolute time, such as ringing a chime every hour on the hour, or running scheduled maintenance every day at a particular time. It is also appropriate for recurring activities where the total time to perform a fixed number of executions is important, such as a countdown timer that ticks once every second for ten seconds. Finally, fixed-rate execution is appropriate for scheduling multiple repeating timer tasks that must remain synchronized with respect to one another.
task
- task to be scheduled.
delay
- delay in milliseconds before task is to be executed.
period
- time in milliseconds between successive task executions.
IllegalArgumentException
- if delay
is negative, or delay + System.currentTimeMillis()
is negative.
IllegalStateException
- if task was already scheduled or cancelled, timer was cancelled, or timer thread terminated.说明:该方法和schedule的相同参数的版本类似,不同的是,如果该任务因为某些原因(例如垃圾收集)而延迟执行,那么接下来的任务会尽可能的快速执行,以赶上特定的时间点。
scheduleAtFixedRate
public void scheduleAtFixedRate (TimerTask task, Date firstTime, long period)
In fixed-rate execution, each execution is scheduled relative to the scheduled execution time of the initial execution. If an execution is delayed for any reason (such as garbage collection or other background activity), two or more executions will occur in rapid succession to "catch up." In the long run, the frequency of execution will be exactly the reciprocal of the specified period (assuming the system clock underlying Object.wait(long) is accurate).
Fixed-rate execution is appropriate for recurring activities that are sensitive to absolute time, such as ringing a chime every hour on the hour, or running scheduled maintenance every day at a particular time. It is also appropriate for recurring activities where the total time to perform a fixed number of executions is important, such as a countdown timer that ticks once every second for ten seconds. Finally, fixed-rate execution is appropriate for scheduling multiple repeating timer tasks that must remain synchronized with respect to one another.
task
- task to be scheduled.
firstTime
- First time at which task is to be executed.
period
- time in milliseconds between successive task executions.
IllegalArgumentException
- if time.getTime()
is negative.
IllegalStateException
- if task was already scheduled or cancelled, timer was cancelled, or timer thread terminated.说明:和上一个方法类似。
下面是我的一个测试片断:
Timer timer = new Timer( false );
timer.schedule( new Worker(), new Date(System.currentTimeMillis() + 1000 ));
}
发表评论
-
飞鸽收藏(转)
2012-04-27 18:18 1367我们常在局域网内用飞鸽进行沟通、文件传输。有天突发奇想,要是我 ... -
主题:边读边写【7】 ----java 多线程实战【Thread /Executors】(转)
2012-04-23 11:39 1391http://www.iteye.com/topic/1122 ... -
牢骚一下,JavaFx 2.0太坑人了
2012-04-18 20:45 17用了半周看了下JavaFx2.0 ,看官方例子感觉还不 ... -
Java中一些关于日期、日期格式、日期的解析和日期的计算 (转)
2012-04-12 11:00 0http://www.blogjava.net/Jkallen ... -
操作property文件(转)
2012-04-12 10:51 966对于一些常量我们经 ... -
Java 系统运行时性能和可用性监控
2012-04-12 10:40 1187简介: 当今的许 ... -
Jconsole_一个监控JVM资源的JDK自带小工具 (转)
2012-04-12 10:32 1223最近一直忙着测一个tomcat的接口,测试中LR总出现2779 ... -
探索JVM运行状态的利器—JVMPI,HPROF_剑_百度空间 (引)
2012-04-12 10:29 1388.什么是JVMPI?Java Virtual ... -
JVM jvmpi (转)
2012-04-12 10:18 1572转自 http://chain.blog.163.com/bl ... -
java 格式化小数
2012-03-09 16:53 1523DecimalFormat 是 NumberForm ... -
org.apache.commons.net.ftp.FTPClient 例子(转)
2012-03-02 09:26 1465转自 http://zhangnet1.iteye.com/b ... -
java查询一次性查询几十万,几百万数据解决办法(转)
2012-02-29 09:15 1004java查询一次性查询几十万,几百万数据解决办法 很早 ... -
java 读取txt,java读取大文件
2012-02-26 19:39 2117java 读取txt,java读取大文件 设置缓存大小 ... -
StringUtils用法+StringUtils详细介绍
2012-02-26 19:38 937StringUtils用法+StringUtils详细介绍博文 ... -
java 字节流网址收藏(暂)
2012-02-07 10:43 751Java I/O关于缓冲区部分提高性能的源码分 ... -
String类substring方法导致的Java内存泄漏问题 (转)
2012-01-06 10:10 1449此问题在项目中被发现,经查看JDK源码(JDK1.6), ... -
Swing 线程之SwingUtilities.invokeLater()(转)
2012-01-06 10:00 1227声明:本文章转自 http://blog.csdn.ne ... -
Swing 线程之SwingUtilities.invokeLater() (转)
2012-01-06 09:59 2声明:本文章转自 http://blog.csdn.net/b ... -
Java Swing GUI多线程之SwingUtilities.invokeLater和invokeAndWait
2012-01-05 16:55 5440在Java中Swing是线程不安全的,是单线程的设计, ... -
ubuntu java配置
2011-12-30 20:54 1084Ubuntu10.10安装sun-Java6-jdk ...
相关推荐
Font Awesome图标字体库提供可缩放矢量图标,它可以被定制大小、颜色、阴影以及任何可以用CSS的样式
介绍了physical design的floorplanning问题
数学建模培训资料 数学建模实战题目真题答案解析解题过程&论文报告 最低生活保障问题的探索 共20页.pdf
变更用水性质定额申请表.xls
从官网上下载下来,作为资源存储,方便安装,此资源为windows版本
嗨玩旅游网站-JAVA-基于springboot嗨玩旅游网站设计与实现(毕业论文+PPT)
【资源说明】 本科毕业设计 基于Python中国知网(cnki)爬虫及数据可视化详细文档+全部资料.zip 【备注】 1、该项目是个人高分项目源码,已获导师指导认可通过,答辩评审分达到95分 2、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 3、本项目适合计算机相关专业(人工智能、通信工程、自动化、电子信息、物联网等)的在校学生、老师或者企业员工下载使用,也可作为毕业设计、课程设计、作业、项目初期立项演示等,当然也适合小白学习进阶。 4、如果基础还行,可以在此代码基础上进行修改,以实现其他功能,也可直接用于毕设、课设、作业等。 欢迎下载,沟通交流,互相学习,共同进步!
api代码
【作品名称】:基于 Java 实现的24点卡牌游戏【课程设计】 【适用人群】:适用于希望学习不同技术领域的小白或进阶学习者。可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。 【项目介绍】: Java小游戏--24点卡牌游戏 将扑克牌(除大小王)随机打乱,每次出现4张卡牌,每张卡牌使用一次,13个回合。 A代表1,J代表11,Q代表12,K代表13。 可2-4人局域网同时在线对战,100秒倒计时结束前回答正确可获得积分,先回答的可获4分,后回答的分数依次递减。 实时显示玩家排名。 【资源声明】:本资源作为“参考资料”而不是“定制需求”,代码只能作为参考,不能完全复制照搬。需要有一定的基础看懂代码,自行调试代码并解决报错,能自行添加功能修改代码。
用 Python 实现的可扩展布隆过滤器皮布卢姆pybloom是一个包含 Bloom Filter 数据结构以及可扩展 Bloom Filter 实现的模块,如下所述P. Almeida、C.Baquero、N. Preguiça、D. Hutchison,可扩展布隆过滤器,(GLOBECOM 2007),IEEE,2007。如果您了解需要提前留出多少位来存储整个集合,那么布隆过滤器就是您的不二之选。可扩展布隆过滤器允许您的布隆过滤器位根据误报概率和大小进行增长。当过滤器达到容量上限时,即为“满”M * ((ln 2 ^ 2) / abs(ln p)),其中 M 是位数,p 是误报概率。当达到容量上限时,将创建一个比上一个过滤器大得多的新过滤器,其误报概率更小,哈希函数数量更多。>>> from pybloom import BloomFilter>>> f = BloomFilter(capacity=1000, error_rate=0.001)>>> [f.add(x) for x in range(10)][False, False, False,
计算机学院宿舍美化大赛.rar
基于java的运动器械购物商城设计与实现.docx
内容概要:文章介绍了针对“卓越工程师教育培养计划”,结合PBL和CDIO工程教育理念,对材料成型及控制工程专业课程设计的实践教学改革进行探索。首先在命题设计上依托企业实践项目,确保设计内容与生产实际紧密结合,具有较强的创新性和实用性。在过程管理中,采用分组合作和面向实际问题导向的教学方法,提升学生的工程素养和创新思维。通过课程设计的成绩考核,结合校内外导师的共同评价,客观全面衡量学生的学习成果。指导教师发挥了组织、支持和引导等多方面的角色作用。 适合人群:高等院校材料成型及控制工程专业学生和教学管理人员;工程教育领域的研究人员。 使用场景及目标:旨在提升工科学生的工程实践能力和创新能力,使其具备解决复杂实际工程问题的能力。通过改革教学内容和方法,改善传统课程设计中存在的不足,培养出高素质的技术人才。 其他说明:改革措施在实际运行中取得了较好的教学效果,提高了学生的就业竞争力,但仍存在一些不足之处需要在未来进行完善。
设计模式学习
C的两数相加求和的程序代码
Viper是一个基于Anno微服务引擎开发的Dashboard示例项目。Anno底层通讯采用grpc、thrift
本教程播放列表涵盖了 Python 中的数据结构和算法。每个教程都有数据结构或算法背后的理论、BIG O 复杂性分析和可供练习的练习。使用 Python 的数据结构和算法本教程涵盖了 Python 中的数据结构和算法。每个教程都包含数据结构或算法背后的理论、BIG O 复杂度分析以及可供练习的练习。要观看视频,您可以访问播放列表https://www.youtube.com/playlist?list=PLeo1K3hjS3uu_n_a__MI_KktGTLYopZ12订阅 codebasics youtube 频道https://www.youtube.com/c/codebasics
python入门——安装Python软件包
就业去向信息-JAVA-基于微信小程序高校毕业生实习及就业去向信息管理系统(毕业论文+PPT)
基于java的学费管理系统设计与实现.docx