Quartz Reschedule作业触发器

时间:2015-12-08 10:31:39

标签: java quartz-scheduler

我是java的新手并且正在尝试学习石英。我有主要方法

public static void main(String[] args) throws SchedulerException {

    try {
        JobDetail job1 = JobBuilder.newJob(Job1.class).withIdentity("job1", "group1").build();

        Trigger trigger1 = TriggerBuilder.newTrigger().withIdentity("cronTrigger1", "group1")
                .withSchedule(CronScheduleBuilder.weeklyOnDayAndHourAndMinute(3, 12, 38)).build();

        Scheduler scheduler1 = new StdSchedulerFactory().getScheduler();
        scheduler1.start();
        scheduler1.scheduleJob(job1, trigger1);

 scheduler1.shutdown();
}

    catch (Exception e) {
     e.printStackTrace();
    }

哪个工作正常。它在一周的第3天下午12:38打印到控制台。 现在,我想要做的是重新安排触发器,以便它删除先前存储的触发器并使用新的计划创建新的触发器。

我在很多地方看了很多东西,但我似乎无法清楚地明白我实际上要做什么,例如:

public void execute(JobExecutionContext context) throws JobExecutionException {
Trigger newTigger = what ever you want;
Trigger oldTrigger = context.getTrigger()
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
scheduler.rescheduleJob(oldTrigger.getKey(), newTrigger);
}

还有这个:

// Define a new Trigger  
Trigger trigger = newTrigger() 
.withIdentity("newTrigger", "group1") 
.startNow() 
.build(); 
// tell the scheduler to remove the old trigger with the given key, and 
// put the new one in its place 
sched.rescheduleJob(triggerKey("oldTrigger", "group1"), trigger);

但我无法理解这种方法(我确实理解代码中发生了什么)。提前谢谢。

0 个答案:

没有答案