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,13 +22,20 @@ 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) {
ThreadPoolTaskExecutor executor = (ThreadPoolTaskExecutor) bean;
executor.setTaskDecorator(TtlRunnable::get);
return executor;
} }
// 修改提交的任务接入 TransmittableThreadLocal // 处理 SimpleAsyncTaskExecutor
ThreadPoolTaskExecutor executor = (ThreadPoolTaskExecutor) bean; // 参考 https://t.zsxq.com/CBoks 增加
executor.setTaskDecorator(TtlRunnable::get); if (bean instanceof SimpleAsyncTaskExecutor) {
return executor; SimpleAsyncTaskExecutor executor = (SimpleAsyncTaskExecutor) bean;
executor.setTaskDecorator(TtlRunnable::get);
return executor;
}
return bean;
} }
}; };