按时间间隔执行
来源:互联网 发布:淘宝如何拍下商品 编辑:程序博客网 时间:2024/04/29 02:41
import java.util.Timer;
import java.util.TimerTask;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Date;
public class FetchMail extends TimerTask {
/**
* Construct and use a TimerTask and Timer.
*/
/**
* Implements TimerTask's abstract run method.
*/
public void run(){
//toy implementation
time=time+1;
System.out.println(time);
}
// PRIVATE ////
private static int time=1;
//expressed in milliseconds
//private final static long fONCE_PER_DAY = 1000*60*60*24;
private final static long fONCE_PER_DAY = 1000*2;
private final static int SECOND = 3;
private final static int fONE_DAY = 1;
private final static int fFOUR_AM = 4;
private final static int fZERO_MINUTES = 0;
private static Date getTomorrowMorning4am(){
Calendar tomorrow = new GregorianCalendar();
//tomorrow.add(Calendar.DATE, fONE_DAY);
tomorrow.add(Calendar.SECOND,fONE_DAY);
Calendar result = new GregorianCalendar(
tomorrow.get(Calendar.YEAR),
tomorrow.get(Calendar.MONTH),
tomorrow.get(Calendar.DATE),
fFOUR_AM,
fZERO_MINUTES
);
System.out.println("11");
return tomorrow.getTime();
}
/**
* Method main
*
*
* @param args
*
*/
public static void main(String[] args) {
// TODO: Add your code here
TimerTask fetchMail = new FetchMail();
Calendar tomorrow = new GregorianCalendar();
//tomorrow.add(Calendar.DATE, fONE_DAY);
tomorrow.add(Calendar.SECOND, SECOND);
System.out.println(tomorrow.getTime());
Calendar tomorrow1 = new GregorianCalendar();
//tomorrow.add(Calendar.DATE, fONE_DAY);
tomorrow1.add(Calendar.SECOND, SECOND+2);
System.out.println(tomorrow1.getTime());
//perform the task once a day at 4 a.m., starting tomorrow morning
//(other styles are possible as well)
Timer timer = new Timer();
timer.scheduleAtFixedRate(fetchMail, getTomorrowMorning4am(), fONCE_PER_DAY);
}
}
- 按时间间隔执行
- AX中实现按时间间隔重复执行动作
- JavaScript 函数队列按时间间隔顺序执行
- 按时间间隔查询统计
- 按时间间隔自动截屏小工具Autoscreencap
- SQL Server 按时间间隔提取数据进行数据采样
- SqlServer 2005 求按时间间隔汇总, 例间隔为五分钟
- 【数据库-MySql】按时间间隔分组查询 group by count(*) date_format
- 【数据库-MySql】按时间间隔分组查询 group by count(*) date_format
- Label字间间隔
- 线程间间隔打印处理
- 使用Stopwatch计算几间间隔
- dbms_job submit后不按时间执行?
- java设置按时间自动执行
- [ZT]crontab 调度程序按时执行
- 按时
- 按时
- 802.11协议帧间间隔-SIFS,DIFS,PIFS,EIFS
- Babylon Pro v6.0.0 (r32)
- 又加班到9点 kao
- Microsoft Windows Vista
- 2006-9-1 数据库共享计划
- 设计模式学习整理之创建型模式
- 按时间间隔执行
- Intel Visual Fortran Compiler Pro 9.1.029
- 文件解压缩操作
- 2006.09.01
- Intel C++ Compiler v9.1.030
- jndi在tomcat中的配置
- 心情(一)
- stuts中上传zip文件,并解压缩
- SQL的数据类型与Java数据类型的对应关系(转)