我有两种不同的石英调度程序。第一个是Cron Scheduler,第二个是Simple Scheduler。 Cron将在我的servlet实例化(init()方法)时启动,而第二个必须在特定时间启动。
问题是第一个调度程序触发第二个调度程序。
public static void startScheduleJobForDBCheck() throws SchedulerException {
log.info("Schedule will start for checking database at the start of each day");
JobDetail job = JobBuilder.newJob(View.class)
.withIdentity("view")
.build();
@SuppressWarnings("rawtypes")
ScheduleBuilder scheduleBuilder =
CronScheduleBuilder.cronSchedule("0 05 0-1 ? * 1-7");
@SuppressWarnings("unchecked")
Trigger trigger = TriggerBuilder.newTrigger().
withSchedule(scheduleBuilder).build();
SchedulerFactory CronchedulerFactory = new StdSchedulerFactory();
Scheduler CronScheduler = CronchedulerFactory.getScheduler();
CronScheduler.scheduleJob(job,trigger);
CronScheduler.start();
}
public static void startScheduleJobForInitialization(int hour,int day,int duration) throws SchedulerException, InterruptedException {
log.info("Schedule will execute the thread at " + hour + " o'clock");
SchedulerFactory SimpleschedulerFactory = new StdSchedulerFactory();
Scheduler simpleScheduler = SimpleschedulerFactory.getScheduler();
JobDetail simpleJob = JobBuilder.newJob(WateringScheduler.class)
.withIdentity("insert")
.build();
simpleJob.getJobDataMap().put("hour", duration);
Calendar c = Calendar.getInstance();
Date date = new Calendar.Builder()
.setDate(c.get(Calendar.YEAR), c.get(Calendar.MONTH), day)
.setTimeOfDay(hour, 13, 0)
.build().getTime();
log.info("Starting date at :" + date);
SimpleTrigger simpletrigger = TriggerBuilder
.newTrigger()
.withIdentity("TriggerOnce", "group1")
.startAt(date)
.withSchedule(SimpleScheduleBuilder.simpleSchedule()
.withIntervalInSeconds(duration)
.withRepeatCount(0)).build();
simpleScheduler.start();
simpleScheduler.scheduleJob(simpleJob, simpletrigger);
}
新的StdSchedulerFactory()不应该实例化一个新对象吗?