feat:【SYSTEM 系统管理】优化支持 SimpleAsyncTaskExecutor 异步线程池

This commit is contained in:
YunaiV 2025-07-09 23:24:17 +08:00
parent bda357508a
commit 569ff42e6f

View File

@ -7,6 +7,7 @@ import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
/** /**
* 异步任务 Configuration * 异步任务 Configuration
@ -21,14 +22,21 @@ public class YudaoAsyncAutoConfiguration {
@Override @Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (!(bean instanceof ThreadPoolTaskExecutor)) { // 处理 ThreadPoolTaskExecutor
return bean; if (bean instanceof ThreadPoolTaskExecutor) {
}
// 修改提交的任务接入 TransmittableThreadLocal
ThreadPoolTaskExecutor executor = (ThreadPoolTaskExecutor) bean; ThreadPoolTaskExecutor executor = (ThreadPoolTaskExecutor) bean;
executor.setTaskDecorator(TtlRunnable::get); executor.setTaskDecorator(TtlRunnable::get);
return executor; return executor;
} }
// 处理 SimpleAsyncTaskExecutor
// 参考 https://t.zsxq.com/CBoks 增加
if (bean instanceof SimpleAsyncTaskExecutor) {
SimpleAsyncTaskExecutor executor = (SimpleAsyncTaskExecutor) bean;
executor.setTaskDecorator(TtlRunnable::get);
return executor;
}
return bean;
}
}; };
} }