ThreadPoolTaskExecutor在执行线程时,存在一个
TaskDecorator
配置,可以装饰线程类。
1. 源码分析
源码:org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#initializeExecutor
@Override protected ExecutorService initializeExecutor(ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
BlockingQueue < Runnable > queue = createQueue(this.queueCapacity);
ThreadPoolExecutor executor;
//配置了线程装饰器
if (this.taskDecorator != null) {
executor = new ThreadPoolExecutor(this.corePoolSize, this.maxPoolSize, this.keepAliveSeconds, TimeUnit.SECONDS, queue, threadFactory, rejectedExecutionHandler) {@Override public void execute(Runnable command) {
//装饰线程类
Runnable decorated = taskDecorator.decorate(command);
if (decorated != command) {
decoratedTas