简体   繁体   中英

How to stop quartz scheduler externally which is running from main method

  public static void main(String[] test) {
        try {

            JobKey jobKeyA = new JobKey("JobAssignVehicleDailyrideFixedVehicle", "group1");
            JobDetail jobA = JobBuilder.newJob(JobAssignVehicleDailyrideFixedVehicle.class)
                    .withIdentity(jobKeyA).build();
            Trigger trigger1 = TriggerBuilder
                    .newTrigger()
                    .withIdentity("Trigger1", "group1")
                    .withSchedule(
                            CronScheduleBuilder.cronSchedule("0/5 * * * * ?"))
                    .build();
                    scheduler = new StdSchedulerFactory().getScheduler();
            scheduler.start();
            scheduler.scheduleJob(jobA, trigger1);
            } catch (SchedulerException e) {
            logger.error(e);
        }
    }

I am running this method from main class from jar file. How can i shutdown quartz properly without just terminating java processes. Is there a way to call shutdown method on scheduler for current running quartz

Use new StdSchedulerFactory().getScheduler() in the Other thread to obtain a reference to the scheduler started in the Main thread.

Why does this work? Invocations of StdSchedulerFactory#getScheduler on both factory instances use the same SchedulerRepository singleton that contains a map of all running quartz schedulers, which in this case is just the default scheduler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM