Java Code Examples for org.quartz.Scheduler#setJobFactory()
The following examples show how to use
org.quartz.Scheduler#setJobFactory() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CronModule.java From attic-aurora with Apache License 2.0 | 6 votes |
@Provides @Singleton Scheduler provideScheduler(AuroraCronJobFactory jobFactory) throws SchedulerException { // There are several ways to create a quartz Scheduler instance. This path was chosen as the // simplest to create a Scheduler that uses a *daemon* QuartzSchedulerThread instance. Properties props = new Properties(); String name = "aurora-cron-" + ID_GENERATOR.incrementAndGet(); props.setProperty(PROP_SCHED_NAME, name); props.setProperty(PROP_SCHED_INSTANCE_ID, name); props.setProperty(PROP_THREAD_POOL_CLASS, SimpleThreadPool.class.getCanonicalName()); props.setProperty( PROP_THREAD_POOL_PREFIX + ".threadCount", String.valueOf(options.cronSchedulerNumThreads)); props.setProperty(PROP_THREAD_POOL_PREFIX + ".makeThreadsDaemons", Boolean.TRUE.toString()); props.setProperty(PROP_SCHED_MAKE_SCHEDULER_THREAD_DAEMON, Boolean.TRUE.toString()); Scheduler scheduler = new StdSchedulerFactory(props).getScheduler(); scheduler.setJobFactory(jobFactory); return scheduler; }
Example 2
Source File: SchedulerFactoryBean.java From spring-analysis-note with MIT License | 4 votes |
private Scheduler prepareScheduler(SchedulerFactory schedulerFactory) throws SchedulerException { if (this.resourceLoader != null) { // Make given ResourceLoader available for SchedulerFactory configuration. configTimeResourceLoaderHolder.set(this.resourceLoader); } if (this.taskExecutor != null) { // Make given TaskExecutor available for SchedulerFactory configuration. configTimeTaskExecutorHolder.set(this.taskExecutor); } if (this.dataSource != null) { // Make given DataSource available for SchedulerFactory configuration. configTimeDataSourceHolder.set(this.dataSource); } if (this.nonTransactionalDataSource != null) { // Make given non-transactional DataSource available for SchedulerFactory configuration. configTimeNonTransactionalDataSourceHolder.set(this.nonTransactionalDataSource); } // Get Scheduler instance from SchedulerFactory. try { Scheduler scheduler = createScheduler(schedulerFactory, this.schedulerName); populateSchedulerContext(scheduler); if (!this.jobFactorySet && !(scheduler instanceof RemoteScheduler)) { // Use AdaptableJobFactory as default for a local Scheduler, unless when // explicitly given a null value through the "jobFactory" bean property. this.jobFactory = new AdaptableJobFactory(); } if (this.jobFactory != null) { if (this.applicationContext != null && this.jobFactory instanceof ApplicationContextAware) { ((ApplicationContextAware) this.jobFactory).setApplicationContext(this.applicationContext); } if (this.jobFactory instanceof SchedulerContextAware) { ((SchedulerContextAware) this.jobFactory).setSchedulerContext(scheduler.getContext()); } scheduler.setJobFactory(this.jobFactory); } return scheduler; } finally { if (this.resourceLoader != null) { configTimeResourceLoaderHolder.remove(); } if (this.taskExecutor != null) { configTimeTaskExecutorHolder.remove(); } if (this.dataSource != null) { configTimeDataSourceHolder.remove(); } if (this.nonTransactionalDataSource != null) { configTimeNonTransactionalDataSourceHolder.remove(); } } }
Example 3
Source File: SchedulerFactoryBean.java From java-technology-stack with MIT License | 4 votes |
private Scheduler prepareScheduler(SchedulerFactory schedulerFactory) throws SchedulerException { if (this.resourceLoader != null) { // Make given ResourceLoader available for SchedulerFactory configuration. configTimeResourceLoaderHolder.set(this.resourceLoader); } if (this.taskExecutor != null) { // Make given TaskExecutor available for SchedulerFactory configuration. configTimeTaskExecutorHolder.set(this.taskExecutor); } if (this.dataSource != null) { // Make given DataSource available for SchedulerFactory configuration. configTimeDataSourceHolder.set(this.dataSource); } if (this.nonTransactionalDataSource != null) { // Make given non-transactional DataSource available for SchedulerFactory configuration. configTimeNonTransactionalDataSourceHolder.set(this.nonTransactionalDataSource); } // Get Scheduler instance from SchedulerFactory. try { Scheduler scheduler = createScheduler(schedulerFactory, this.schedulerName); populateSchedulerContext(scheduler); if (!this.jobFactorySet && !(scheduler instanceof RemoteScheduler)) { // Use AdaptableJobFactory as default for a local Scheduler, unless when // explicitly given a null value through the "jobFactory" bean property. this.jobFactory = new AdaptableJobFactory(); } if (this.jobFactory != null) { if (this.applicationContext != null && this.jobFactory instanceof ApplicationContextAware) { ((ApplicationContextAware) this.jobFactory).setApplicationContext(this.applicationContext); } if (this.jobFactory instanceof SchedulerContextAware) { ((SchedulerContextAware) this.jobFactory).setSchedulerContext(scheduler.getContext()); } scheduler.setJobFactory(this.jobFactory); } return scheduler; } finally { if (this.resourceLoader != null) { configTimeResourceLoaderHolder.remove(); } if (this.taskExecutor != null) { configTimeTaskExecutorHolder.remove(); } if (this.dataSource != null) { configTimeDataSourceHolder.remove(); } if (this.nonTransactionalDataSource != null) { configTimeNonTransactionalDataSourceHolder.remove(); } } }
Example 4
Source File: QuartzSchedulerProvider.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
private Scheduler createScheduler() { try { // ensure executed threads have TCCL set ThreadExecutor threadExecutor = new DefaultThreadExecutor() { @Override public void execute(final Thread thread) { thread.setContextClassLoader(QuartzSchedulerProvider.class.getClassLoader()); super.execute(thread); } }; // create Scheduler (implicitly registers it with repository) DirectSchedulerFactory.getInstance().createScheduler( SCHEDULER_NAME, nodeAccess.getId(), // instance-id new QuartzThreadPool(threadPoolSize, threadPriority), threadExecutor, jobStore.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 s = DirectSchedulerFactory.getInstance().getScheduler(SCHEDULER_NAME); s.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{}", s.getMetaData().getVersion()); s.standby(); return s; } catch (Exception e) { throw new RuntimeException(e); } }