How to add job with trigger for running Quartz sch

2019-08-05 11:03发布

问题:

I want to create one scheduler instance then adding Jobs and triggers for future use to this scheduler running by web UI without restarting server (I use Quartz 2.x version) Can anybody help me please?

Thanks

回答1:

You can dynamically add jobs to a Quartz scheduler instance but the jobs (i.e. the job classes) must be typically present on the Quartz scheduler's classpath. Alternatively you could use the Quartz scheduler's JobFactory API to load job classes through a custom class-loader and that would allow you to add jobs truly dynamically.

With triggers, there is no problem at all - these can be added/updated/deleted dynamically using the standard Quartz API.

As for a GUI that allows you to add jobs/triggers, there are couple of them and you can easily find them by searching for "quartz scheduler gui" on Google.

I happen to be a principal developer of QuartzDesk, which is one of those products. If you have any questions regarding this product, then please use our contacts.



回答2:

thank you for your answer, I rephrase my question,

I want to create ONE SCHEDULER instance and add FIVE JOBS with PARAMETRES. Then i want to dynamically add TRIGGERS to this jobs for future use by web UI without restarting server. And with each trigger, I want to send parameters to the JOB to perform a specific processing

Exemple:

public class SendSMS implements Job {

public void execute(JobExecutionContext jec) throws JobExecutionException {
    try {
        SendMessage(param1, param2, param3);
    } catch (Exception e) {
        throw new UnsupportedOperationException("Erreur : " + e.getStackTrace());
    }
}

}

public class CronTriggers {

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

    JobKey jobKeySMS = new JobKey("SMSJob", "Groupe1");
    JobDetail jobDetailSMS = JobBuilder.newJob(SendSMS.class).withIdentity(jobKeySMS).build();

    Scheduler scheduler = new StdSchedulerFactory().getScheduler();
    scheduler.clear();
    scheduler.start();

    scheduler.scheduleJob(jobDetailSMS, DYNAMIC_TRIGGER); // DYNAMIC_TRIGGER recover from web UI

Thanks