下面列出了怎么用org.quartz.simpl.RAMJobStore的API类实例代码及写法,或者点击链接到github查看源代码。
private Properties getProperties() {
Properties props = new Properties();
props.setProperty("org.quartz.jobStore.class", quartzConfig.getJobStore().getName());
props.setProperty("org.quartz.threadPool.threadCount", String.valueOf(quartzConfig.getThreads()));
if (!quartzConfig.getJobStore().equals(RAMJobStore.class)) {
props.setProperty("org.quartz.jobStore.driverDelegateClass", quartzConfig.getDbDelegate().getName());
props.setProperty("org.quartz.jobStore.dataSource", "main");
props.setProperty("org.quartz.dataSource.main.driver", dbConfig.getDriverClass());
props.setProperty("org.quartz.dataSource.main.URL", dbConfig.getUrl());
props.setProperty("org.quartz.dataSource.main.user", dbConfig.getUser());
props.setProperty("org.quartz.dataSource.main.password", dbConfig.getPassword());
}
return props;
}
/**
* Creates an in memory job store (<code>{@link RAMJobStore}</code>)
* The thread priority is set to Thread.NORM_PRIORITY
*
* @param maxThreads
* The number of threads in the thread pool
* @throws SchedulerException
* if initialization failed.
*/
public void createVolatileScheduler(int maxThreads)
throws SchedulerException {
SimpleThreadPool threadPool = new SimpleThreadPool(maxThreads,
Thread.NORM_PRIORITY);
threadPool.initialize();
JobStore jobStore = new RAMJobStore();
this.createScheduler(threadPool, jobStore);
}
@Bean
public Scheduler quartzScheduler(ApplicationContext context) throws Exception {
SchedulerFactoryBean factory = new SchedulerFactoryBean();
factory.setApplicationContext(context);
factory.setExposeSchedulerInRepository(true);
factory.setApplicationContextSchedulerContextKey(APPLICATION_CONTEXT_KEY);
factory.setJobFactory(glassJobFactory);
Properties properties = new Properties();
properties.setProperty("org.quartz.scheduler.skipUpdateCheck","true");
properties.setProperty("org.quartz.threadPool.class", SimpleThreadPool.class.getName());
properties.setProperty("org.quartz.threadPool.threadCount", "15");
properties.setProperty("org.quartz.threadPool.threadPriority", "4");
if (configuration().isInMemory()) {
properties.setProperty("org.quartz.jobStore.class", RAMJobStore.class.getName());
} else {
factory.setDataSource(dataSource());
properties.setProperty("org.quartz.jobStore.tablePrefix", configuration().getTablePrefix());
properties.setProperty("org.quartz.jobStore.isClustered", "false");
properties.setProperty("org.quartz.jobStore.driverDelegateClass", configuration().getDriverDelegateClass());
}
factory.setQuartzProperties(properties);
factory.afterPropertiesSet();
Scheduler scheduler = factory.getObject();
scheduler.getListenerManager().addJobListener(glassJobListener);
scheduler.getListenerManager().addSchedulerListener(glassSchedulerListener);
scheduler.start();
return scheduler;
}
/**
* Creates an in memory job store (<code>{@link RAMJobStore}</code>)
* The thread priority is set to Thread.NORM_PRIORITY
*
* @param maxThreads
* The number of threads in the thread pool
* @throws SchedulerException
* if initialization failed.
*/
public void createVolatileScheduler(int maxThreads)
throws SchedulerException {
SimpleThreadPool threadPool = new SimpleThreadPool(maxThreads,
Thread.NORM_PRIORITY);
threadPool.initialize();
JobStore jobStore = new RAMJobStore();
this.createScheduler(threadPool, jobStore);
}