Commit 569ff42e6f9d2a4499ca0cfe113585e705ab59f2

Authored by YunaiV
1 parent bda35750

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

yudao-framework/yudao-spring-boot-starter-job/src/main/java/cn/iocoder/yudao/framework/quartz/config/YudaoAsyncAutoConfiguration.java
@@ -7,6 +7,7 @@ import org.springframework.boot.autoconfigure.AutoConfiguration; @@ -7,6 +7,7 @@ import org.springframework.boot.autoconfigure.AutoConfiguration;
7 import org.springframework.context.annotation.Bean; 7 import org.springframework.context.annotation.Bean;
8 import org.springframework.scheduling.annotation.EnableAsync; 8 import org.springframework.scheduling.annotation.EnableAsync;
9 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; 9 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
  10 +import org.springframework.core.task.SimpleAsyncTaskExecutor;
10 11
11 /** 12 /**
12 * 异步任务 Configuration 13 * 异步任务 Configuration
@@ -21,13 +22,20 @@ public class YudaoAsyncAutoConfiguration { @@ -21,13 +22,20 @@ public class YudaoAsyncAutoConfiguration {
21 22
22 @Override 23 @Override
23 public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { 24 public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
24 - if (!(bean instanceof ThreadPoolTaskExecutor)) {  
25 - return bean; 25 + // 处理 ThreadPoolTaskExecutor
  26 + if (bean instanceof ThreadPoolTaskExecutor) {
  27 + ThreadPoolTaskExecutor executor = (ThreadPoolTaskExecutor) bean;
  28 + executor.setTaskDecorator(TtlRunnable::get);
  29 + return executor;
26 } 30 }
27 - // 修改提交的任务,接入 TransmittableThreadLocal  
28 - ThreadPoolTaskExecutor executor = (ThreadPoolTaskExecutor) bean;  
29 - executor.setTaskDecorator(TtlRunnable::get);  
30 - return executor; 31 + // 处理 SimpleAsyncTaskExecutor
  32 + // 参考 https://t.zsxq.com/CBoks 增加
  33 + if (bean instanceof SimpleAsyncTaskExecutor) {
  34 + SimpleAsyncTaskExecutor executor = (SimpleAsyncTaskExecutor) bean;
  35 + executor.setTaskDecorator(TtlRunnable::get);
  36 + return executor;
  37 + }
  38 + return bean;
31 } 39 }
32 40
33 }; 41 };