好记性不如烂博客之 Quartz HowTo: Update an existing job

接上一篇中 如果动态更新一个任务的计划(Trigger)http://www.cnblogs.com/daxin/archive/2013/05/30/3109296.html

这篇主要介绍的是如何动态替换一个任务,即动态的用 任务2 替换 任务1

 

        //SimpleJob新的任务类
        JobBuilder job1 = JobBuilder.newJob(SimpleJob.class);
        //与要替换的任务具有相同的name与group
        job1.withIdentity("name1", "group1");
        //这里一定设为true
        job1.storeDurably(true);
        JobDetail d2 = job1.build();
        
        //替换
        scheduler.addJob(d2, true);

// Add the new job to the scheduler, instructing it to "replace"
//  the existing job with the given name and group (if any)
JobDetail job1 = newJob(MyJobClass.class)
    .withIdentity("job1", "group1")
    .build();

// store, and set overwrite flag to 'true'     
scheduler.addJob(job1, true);
原文地址:https://www.cnblogs.com/daxin/p/3109329.html