我有一个计时器ejb,用于控制何时运行需要切换的应用程序。我需要让它在每天0200点运行
public void fireInTwentyFourHours() throws EJBException
TimerService theTimerService = mySessionCtx.getTimerService();
String aLabel = "24 Hours Interval";
//theTimerService.createTimer(new Date(),86400000, aLabel);
String stage = Stage.getStage();
List timerObjects = (List)theTimerService.getTimers();
if(null != timerObjects && timerObjects.size() > 0) {
for(int timerCount=0,size=timerObjects.size();timerCount<size;timerCount++) {
Timer timer = (Timer)timerObjects.get(timerCount);
timer.cancel();
}
}
if(stage.equalsIgnoreCase("P")){
theTimerService.createTimer(getRunTime(),86400000, aLabel);
} else {
theTimerService.createTimer(new Date(),86400000, aLabel);
}
}
private Date getRunTime() {
Calendar gc = new GregorianCalendar();
int year = gc.get(Calendar.YEAR);
int month = gc.get(Calendar.MONTH);
int date = gc.get(Calendar.DAY_OF_MONTH);
Calendar newDate = new GregorianCalendar(year,month,date,17,30,0);
return newDate.getTime();
}
我需要创建一个新方法,并让f ireInTwentyFourHours
在0200时执行。
这是在0200
点火的正确方法吗?public Date getTime(){
Calendar c = Calendar.getInstance();
Date d = c.getTime();
return d;
}
public void fireInTwentyFourHours() throws EJBException
TimerService theTimerService = mySessionCtx.getTimerService();
String aLabel = "24 Hours Interval";
//theTimerService.createTimer(new Date(),86400000, aLabel);
String stage = Stage.getStage();
List timerObjects = (List)theTimerService.getTimers();
if(null != timerObjects && timerObjects.size() > 0) {
for(int timerCount=0,size=timerObjects.size();timerCount<size;timerCount++) {
Timer timer = (Timer)timerObjects.get(timerCount);
timer.cancel();
}
}
if(stage.equalsIgnoreCase("P")){
theTimerService.createIntervalTimer(getTime(),86400000, aLabel);
} else {
theTimerService.createIntervalTimer(new Date(),86400000, aLabel);
}
}
第三个参数是timerConfig如何设置。它会使代码在0200运行吗?