Quartz,启动不立即执行问题

Quartz,启动不立即执行问题

我的Quartz 是2.2版本,

在java程序中写了两个加入计划方法


////  添加简单计划任务 author:iresearch.com.cn -- jackical
     public static void AddSimplejob(String jobName,String strTrigger, int id, int hour, int minute,Date DateStart) throws SchedulerException{
         
         Scheduler sched=sf.getScheduler();
         
         Calendar calendar=GregorianCalendar.getInstance();
         calendar.setTime(DateStart);
         int intYear= calendar.get(Calendar.YEAR);
         int intMonth=calendar.get(Calendar.MONTH)+ 1 ;
         int intDay=calendar.get(Calendar.DAY_OF_MONTH);
         
         Date runDate=DateBuilder.dateOf(hour, minute, 0 ,intDay,intMonth,intYear);   //////  设置执行的时间
         
         JobDetail jobDetail=JobBuilder.newJob(DoJob. class )
                 .withIdentity(jobName,JOB_GROUP_NAME)
                 .usingJobData( "id" ,id)
                 .build();
         
         SimpleTrigger trigger=(SimpleTrigger)TriggerBuilder
                 .newTrigger()
                 .withIdentity(strTrigger,TRIGGER_GROUP_NAME)
                 .startAt(runDate)
                 .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                         .withIntervalInMinutes( 3 )
                         .withRepeatCount( 0 )
                         )
                 .build();
         
         /*
          *              .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                         .withIntervalInSeconds(10)
                         .withRepeatCount(0)
                         )
          * */
         
         sched.scheduleJob(jobDetail,trigger);
         sched.start();
     }
     
     /////  添加定时任务 author:iresearch.com.cn -- jackical
     public static void AddCronJob(String jobName,String strTrigger, int id,String strExp,Date DateStart,Date DateEnd) throws SchedulerException, ParseException{
         
         Scheduler sched=sf.getScheduler();
         
         JobDetail jobDetail=JobBuilder.newJob(DoJob. class )
                 .withIdentity(jobName,JOB_GROUP_NAME)
                 .usingJobData( "id" ,id)
                 .build();
         
         Trigger trigger=(CronTrigger)TriggerBuilder
                 .newTrigger()
                 .withIdentity(strTrigger,TRIGGER_GROUP_NAME)
                 .startAt(DateStart)
                 .endAt(DateEnd)
                 .withSchedule(CronScheduleBuilder.cronSchedule(strExp)
                         .withMisfireHandlingInstructionDoNothing()
                         )
                 .build();
         
         
         sched.scheduleJob(jobDetail,trigger);
         sched.start();
         
     }

你可能感兴趣的:(Quartz,启动不立即执行问题)