quartz中的线程池

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

quartz中的线程池
书接上回:
定时器要调度多个定时任务,就得有⼀个线程池来进⾏任务的并发处理,那来看下quartz中的线程池情况。

SchedulerFactory schedulerFactory = new StdSchedulerFactory();
Scheduler scheduler = schedulerFactory.getScheduler();
当执⾏schedulerFactory.getScheduler()时,会初始化⼀个线程池SimpleThreadPool,过程如下:
// Get ThreadPool Properties
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
String tpClass = cfg.getStringProperty(PROP_THREAD_POOL_CLASS, SimpleThreadPool.class.getName());
if (tpClass == null) {
initException = new SchedulerException(
"ThreadPool class not specified. ");
throw initException;
}
try {
tp = (ThreadPool) loadHelper.loadClass(tpClass).newInstance();
} catch (Exception e) {
initException = new SchedulerException("ThreadPool class '"
+ tpClass + "' could not be instantiated.", e);
throw initException;
}
SimpleThreadPool是⼀个⽐较简单的线程池实现,只有线程数这⼀个属性,不像其他功能⽐较丰富的线程池有像核⼼线程数、最⼤线程数、队列⼤⼩等参数。

默认线程数为10,实际运⾏起来的情况如下截图:
那如何修改线程数呢?
可采⽤如下⽅式:
Properties prop = new Properties();
// 线程池配置
prop.put("org.quartz.threadPool.threadCount", "20");
SchedulerFactory schedulerFactory = new StdSchedulerFactory(prop);
Scheduler scheduler = schedulerFactory.getScheduler();
那如何定义⼀个功能⽐较丰富的线程池给quartz使⽤呢(当然很少这样哈)
以下为⽹上看到的⼀个参考实现,连接如下,感谢分享:。

相关文档
最新文档