ScheduledExecutorService的用法——定时执行两个任务
package control; import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; public class TimerManager {
//
Log log=Log.getLoger(); private ScheduledExecutorService scheduExec;
public long start;
public TimerManager() { this.scheduExec = Executors.newScheduledThreadPool(2); this.start = System.currentTimeMillis();
long oneDay = 24 * 60 * 60 * 1000;
long initDelayOne = getTimeMillis("3:00:00") - System.currentTimeMillis();
initDelayOne = initDelayOne > 0 ? initDelayOne : oneDay + initDelayOne;
long initDelayTwo = getTimeMillis("3:00:00") - System.currentTimeMillis();
initDelayTwo = initDelayTwo > 0 ? initDelayTwo : oneDay + initDelayTwo; } public void timerOne(){
scheduExec.scheduleWithFixedDelay(new Runnable() {
public void run() {
...
System.out.println("timerOne invoked ....."); }
},0,5000, TimeUnit.MILLISECONDS);
} public void timerTwo(){
scheduExec.scheduleAtFixedRate(new Runnable() {
public void run() {
...
System.out.println("timerTwo invoked .....");
}
},2000,5000,TimeUnit.MILLISECONDS); } /**
* @param time "HH:mm:ss"
* @return
*/
private static long getTimeMillis(String time) {
try {
DateFormat dateFormat = new SimpleDateFormat("yy-MM-dd HH:mm:ss");
DateFormat dayFormat = new SimpleDateFormat("yy-MM-dd");
Date curDate = dateFormat.parse(dayFormat.format(new Date()) + " " + time);
return curDate.getTime();
} catch (ParseException e) {
e.printStackTrace();
}
return 0;
} public static void main(String[] args) {
TimerManager test = new TimerManager();
test.timerOne();
}
}
ScheduledExecutorService的用法——定时执行两个任务的更多相关文章
- linux定时执行任务crontab命令用法
linux系统的定时任务是由 cron (crond) 这个系统服务来控制的.Linux 系统上面原本就有非常多的计划性工作,因此这个系统服务是默认启动的.另外, 由于使用者自己也可以设置计划任务,所 ...
- Oracle通过JOB定时执行存储过程实现两表数据比对
需求: 第三方云平台管理的虚拟机会进行关机.资源扩展等操作,因此开关机状态.CPU.内存.磁盘大小等数据需要进行同步.这里第三方云平台是BMC CLM云平台,底层虚拟化平台是Vcenter.进行同步的 ...
- 【转】linux 定时执行shell脚本
在oracle 中可以利用dbms_job包定时执行pl/sql.sql过程,在像备份等需要在操作系统级定时任务只能采用crontab来完成 本文讲述crontab具体用法,以供备忘. 在oracle ...
- Linux下定时执行脚本(转自Decode360)
文章来自:http://www.blogjava.net/decode360/archive/2009/09/18/287743.html Decode360's Blog 老师(业精于勤而荒于嬉 ...
- 如何使用Linux的Crontab定时执行PHP脚本的方法
我们的PHP程序有时候需要定时执行,我们可以使用ignore_user_abort函数或是在页面放置js让用户帮我们实现.但这两种方法都不太可靠,不稳定.我们可以借助Linux的Crontab工具来稳 ...
- Linux下的crontab定时执行任务命令详解
在LINUX中,周期执行的任务一般由cron这个守护进程来处理[ps -ef|grep cron].cron读取一个或多个配置文件,这些配置文件中包含了命令行及其调用时间.cron的配置文件称为“cr ...
- crontab定时执行任务
第一部分 crontab介绍 每个操作系统都有它的自动定时启动程序的功能,Windows有它的任务计划,而Linux对应的功能是crontab. crontab简介 crontab命令常见于Unix和 ...
- 关于oracle dbms_job 定时执行的内容。
一.设置初始化参数 job_queue_processessql> alter system set job_queue_processes=n;(n>0)job_queue_proces ...
- linux 定时执行shell脚本
转自:http://blog.csdn.net/jingxiangren/article/details/4745631 在oracle 中可以利用dbms_job包定时执行pl/sql.sql过程, ...
随机推荐
- DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements SingletonBeanRegistry
// 用于内部标记的空的单例对象(不支持null)protected static final Object NULL_OBJECT = new Object(); // 缓存单例对象根据beanNa ...
- android 读取串口数据的服务
2016-09-1813:10:03 继承Service,定义抽象方法onDataReceived,子类通过实现抽象方法获取接收到数据的回调. package com.zrsoft.liftad.se ...
- HTML+CSS实例——漂亮的查询部件(一)
一.参考网址:www.kuhnsjewelers.com 二.效果: 三.HTML <div id="search-box"> <asp:TextBox ID=& ...
- Zabbix Api的使用
API使用 zabbix官网文档:https://www.zabbix.com/documentation/2.2/manual/api, Zabbix API是基于JSON-RPC 2.0规格,具体 ...
- template和templateUrl区别与联系
templateUrl其实根template功能是一样的,只不过templateUrl加载一个html文件,template后面根的是html的标签. .state('menu.about', { u ...
- Ventuz配置Leap Motion环境
1.下载Leap Dev Kit 前往官网www.leapmotion.com,下载相应平台的开发包,目前PC版的最新版本为2.3.1. SDK里包含了Leap Motion的安装包,上图第二个.安装 ...
- CXF(2.7.10) - RESTful Services
1. 定义 JavaBean.注意 @XmlRootElement 注解,作用是将 JavaBean 映射成 XML 元素. package com.huey.demo.bean; import ja ...
- Jersey(1.19.1) - Security
Security information is available by obtaining the SecurityContext using @Context, which is essentia ...
- NPOI读取Excel表格类
public class NPOIHelper { private HSSFWorkbook workbook; public static IWorkbook Lo ...
- 转....导入excel错误:外部表不是预期的格式 解决方案
环境:win7+iis7+Office2007 在asp.net网站中导出Excel文件后,再把文件导入到数据库中. 读取Excel文件时,打开连接出错. 错误为:外部表不是预期的格式 解决:检查了一 ...