Scheduler 工厂分别是 org.quartz.impl.DirectSchedulerFactory 和 org.quartz.impl.StdSchedulerFactory
DirectSchedulerFactory 是为精细化控制 Scheduler 实例产生的工厂类,一般不用,不过有利于理解quartz内部组件。
-- 最简单 public void createScheduler(ThreadPool threadPool, JobStore jobStore); -- 最复杂 public void createScheduler(String schedulerName, String schedulerInstanceId,ThreadPool threadPool, JobStore jobStore, String rmiRegistryHost, int rmiRegistryPort);
public scheduler createScheduler(){
DirectSchedulerFactory factory=DirectSchedulerFactory.getInstance();
try {
//创建线程池
SimpleThreadPool threadPool = new SimpleThreadPool(10, Thread.NORM_PRIORITY);
threadPool.initialize();
//创建job存储类
JobStoreTX jdbcJobStore = new JobStoreTX();
jdbcJobStore.setDataSource("someDatasource");
jdbcJobStore.setPostgresStyleBlobs(true);
jdbcJobStore.setTablePrefix("QRTZ_");
jdbcJobStore.setInstanceId("My Instance");
logger.info("Scheduler starting up...");
factory.createScheduler(threadPool,jdbcJobStore);
// Get a scheduler from the factory
Scheduler scheduler = factory.getScheduler();
// 必须启动scheduler
scheduler.start();
return scheduler;
}
return null;
}
org.quartz.impl.StdSchedulerFactory 依赖于属性类(Properties)决定如何生产 Scheduler 实例
通过加载属性文件,Properties 提供启动参数:
public scheduler createScheduler(){
// Create an instance of the factory
StdSchedulerFactory factory = new StdSchedulerFactory();
// Create the properties to configure the factory
Properties props = new Properties();
// required to supply threadpool class and num of threads
props.put(StdSchedulerFactory.PROP_THREAD_POOL_CLASS,"org.quartz.simpl.SimpleThreadPool");
props.put("org.quartz.threadPool.threadCount", "10");
try {
// Initialize the factory with properties
factory.initialize(props);
Scheduler scheduler = factory.getScheduler();
logger.info("Scheduler starting up...");
scheduler.start();
} catch (SchedulerException ex) {
logger.error(ex);
}
}
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-29777-4.html
一个浙江财经学院教授在研究问题时就只有一个3000万的推测数据吗
他的钱咋来的呢