Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 每天凌晨2点运行计时器任务_Java_Timer_Ejb - Fatal编程技术网

Java 每天凌晨2点运行计时器任务

Java 每天凌晨2点运行计时器任务,java,timer,ejb,Java,Timer,Ejb,我有一个计时器ejb,它控制需要切换的应用程序何时运行。我需要让它每天凌晨两点运行 public void fireInTwentyFourHours() throws EJBException TimerService theTimerService = mySessionCtx.getTimerService(); String aLabel = "24 Hours Interval"; //theTimerService.createTimer(ne

我有一个计时器ejb,它控制需要切换的应用程序何时运行。我需要让它每天凌晨两点运行

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();
    }

第三个参数是timerConfig如何设置。它会使代码在0200运行吗?

将日历转换为日期并使用,java.io.Serializable)@ScaryWombat我添加了一个代码使其在0200运行。但是如何将timerconfig设置为createIntervalTimer方法中的第三个参数呢
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);
              }
            }