我有兩個計時器。然後每5分鐘運行一次,另一次運行10分鐘。一旦我運行該應用程序它可以很好地工作,但在11:50之後它會停止執行。午夜後不啓動計時器
我的代碼如下:
//At minute 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, and 55 past every hour from 0 through 4 and every hour.
for(int hrsTime=1;hrsTime<=4;hrsTime++){
System.out.println("hours start time : "+hrsTime);
_log.info("MrkRomeFiles hours start time : "+hrsTime);
start_1=0;
for(int i=0;i<11;i++){
Calendar today = Calendar.getInstance();
today.set(Calendar.HOUR_OF_DAY, hrsTime);//everyday 1,2,3 and 4 oclock
today.set(Calendar.MINUTE, start_1);
today.set(Calendar.SECOND, 0);
timer.schedule(new MrkRomeFiles(_env), today.getTime(), TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS));
System.out.println("minuts start time : "+start_1);
_log.info("MrkRomeFiles minuts start time : "+start_1);
start_1=start_1+5;
}
}
//At minute 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, and 55 past every hour from 8 through 23 every hour.
for(int startTime=8;startTime<=23;startTime++){
int start=0;
System.out.println("hours start time : "+startTime);
_log.info("MrkRomeFiles hours start time : "+startTime);
for(int i=0;i<11;i++){
System.out.println("minuts start time : "+start);
_log.info("MrkRomeFiles minuts start time : "+start);
Calendar today = Calendar.getInstance();
today.set(Calendar.HOUR_OF_DAY, startTime);
today.set(Calendar.MINUTE, start);
today.set(Calendar.SECOND, 0);
timer.schedule(new MrkRomeFiles(_env), today.getTime(), TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS));
start=start+5;
}
}
//this is for run every 10min
for(int startTime=0;startTime<=23;startTime++){
_log.info("oracle hour time : : "+startTime);
System.out.println("oracle hour time : "+startTime);
int startOraMinutes=0;
for(int i=0;i<6;i++){
Calendar today = Calendar.getInstance();
today.set(Calendar.HOUR_OF_DAY, startTime);
today.set(Calendar.MINUTE, startOraMinutes);
today.set(Calendar.SECOND, 0);
timer.schedule(new MrkOraFiles(_env), today.getTime(), TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS));
_log.info("oracle minuts time : "+startOraMinutes);
System.out.println("oracle minuts time : "+startOraMinutes);
startOraMinutes=startOraMinutes+10;
}
}
低於是其上印有日誌:
2017-02-28 23:40:00,556 [ MrkRomeFiles.java:Timer-0:600] - mrkRome file start execution at 2017/02/28 23:40:00
2017-02-28 23:40:00,616 [ MrkOraFiles.java:Timer-0:179] - mrkOra file start execution at : 2017/02/28 23:40:00
2017-02-28 23:40:00,627 [ MrkOraFiles.java:Timer-0:179] - mrkOra file start execution at : 2017/02/28 23:40:00
2017-02-28 23:45:00,557 [ MrkRomeFiles.java:Timer-0:600] - mrkRome file start execution at 2017/02/28 23:45:00
2017-02-28 23:50:00,557 [ MrkRomeFiles.java:Timer-0:600] - mrkRome file start execution at 2017/02/28 23:50:00
2017-02-28 23:50:00,617 [ MrkOraFiles.java:Timer-0:179] - mrkOra file start execution at : 2017/02/28 23:50:00
2017-02-28 23:50:00,627 [ MrkOraFiles.java:Timer-0:179] - mrkOra file start execution at : 2017/02/28 23:50:00
您是否準確在午夜運行這些循環?或者在任何時候應用程序啓動? – RealSkeptic