哪位大神知道 spring封装的线程池 源码里面
ExecutorConfigurationSupport
成员变量
private ExecutorService executor;
ThreadPoolTaskExecutor类 继承ExecutorConfigurationSupport类
成员变量
private ThreadPoolExecutor threadPoolExecutor;
方法
protected ExecutorService initializeExecutor(
ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
BlockingQueue queue = createQueue(this.queueCapacity);
ThreadPoolExecutor executor = new ThreadPoolExecutor(this.corePoolSize, this.maxPoolSize, this.keepAliveSeconds, TimeUnit.SECONDS,queue, threadFactory, rejectedExecutionHandler);
if (this.allowCoreThreadTimeOut) {
executor.allowCoreThreadTimeOut(true);
}
this.threadPoolExecutor = executor;
return executor;
}
ThreadPoolTaskExecutor任务执行是采用的自身成员变量
private ThreadPoolExecutor threadPoolExecutor;
那么父类ExecutorConfigurationSupport的成员变量private ExecutorService executor;虽然初始化了,实际没有用到
请问这里面是什么原因?
ExecutorConfigurationSupport类初始化方法
public void initialize() {
if (logger.isInfoEnabled()) {
logger.info("Initializing ExecutorService " + (this.beanName != null ? " '" + this.beanName + "'" : ""));
}
if (!this.threadNamePrefixSet && this.beanName != null) {
setThreadNamePrefix(this.beanName + "-");
}
this.executor = initializeExecutor(this.threadFactory, this.rejectedExecutionHandler);
}
抽象方法由子类ThreadPoolTaskExecutor实现
protected abstract ExecutorService initializeExecutor(
ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler);