How to stop an external quartz scheduler that runs from the 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 the main class from the jar file. How can I close quartz properly without stopping Java processes. Is there a way to call the shutdown method for the scheduler for the currently running quartz.
+3
source to share
1 answer
Use new StdSchedulerFactory().getScheduler()
on another thread to get a link to the scheduler running on the main thread.
Why does it work? The calls to StdSchedulerFactory # getScheduler on both factory instances use the same SchedulerRepository singleton, which contains a map of all running quartz schedulers, which in this case is only the default scheduler.
+3
source to share