/** * Create a new {@link Scheduler} and set to stand-by mode. */ private Scheduler createScheduler() throws SchedulerException { // ensure executed threads have TCCL set ThreadExecutor threadExecutor = new DefaultThreadExecutor() { @Override public void execute(final Thread thread) { thread.setContextClassLoader(QuartzSchedulerSPI.class.getClassLoader()); super.execute(thread); } }; // create Scheduler (implicitly registers it with repository) DirectSchedulerFactory.getInstance().createScheduler( SCHEDULER_NAME, nodeAccess.getId(), // instance-id new QuartzThreadPool(threadPoolSize), threadExecutor, jobStoreProvider.get(), null, // scheduler plugin-map null, // rmi-registry host 0, // rmi-registry port -1, // idle-wait time -1, // db-failure retry-interval true, // jmx-export null, // custom jmx object-name, lets use the default 1, // max batch-size 0L // batch time-window ); Scheduler scheduler = DirectSchedulerFactory.getInstance().getScheduler(SCHEDULER_NAME); scheduler.setJobFactory(jobFactory); // re-logging with version, as by default we limit quartz logging to WARN, hiding its default version logging log.info("Quartz Scheduler v{}", scheduler.getMetaData().getVersion()); scheduler.standby(); return scheduler; }
private QuartzScheduler getScheduler() { Logger logger = LoggerFactory.getLogger(this.getClass()); if (scheduler == null) { try { QuartzSchedulerResources qsr = getQuartzSchedulerResources(); if (qsr.getThreadExecutor() == null) { qsr.setThreadExecutor(new DefaultThreadExecutor()); } qsr.getThreadPool().initialize(); QuartzScheduler qs = new QuartzScheduler(qsr, getDefaultIdleWaitTime(), -1); ClassLoadHelper classLoadHelper = getJobStoreClassLoadHelper(); classLoadHelper.initialize(); qsr.getJobStore().initialize(classLoadHelper, qs.getSchedulerSignaler()); qsr.getJobRunShellFactory().initialize(this); qs.initialize(); qs.setJobFactory(getInitialJobFactory()); logger.info("Quartz scheduler '" + qsr.getName()); logger.info("Quartz scheduler version: " + qs.getVersion()); scheduler = qs; } catch (Exception ex) { logger.error("Exception creating scheduler!", ex); } } return scheduler; }