提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.framework.quartz.config; |
H |
2 |
|
|
3 |
import com.alibaba.ttl.TtlRunnable; |
|
4 |
import org.springframework.beans.BeansException; |
|
5 |
import org.springframework.beans.factory.config.BeanPostProcessor; |
|
6 |
import org.springframework.boot.autoconfigure.AutoConfiguration; |
|
7 |
import org.springframework.context.annotation.Bean; |
|
8 |
import org.springframework.context.annotation.Configuration; |
|
9 |
import org.springframework.scheduling.annotation.EnableAsync; |
|
10 |
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
|
11 |
|
|
12 |
/** |
|
13 |
* 异步任务 Configuration |
|
14 |
*/ |
|
15 |
@AutoConfiguration |
|
16 |
@EnableAsync |
|
17 |
public class IailabAsyncAutoConfiguration { |
|
18 |
|
|
19 |
@Bean |
|
20 |
public BeanPostProcessor threadPoolTaskExecutorBeanPostProcessor() { |
|
21 |
return new BeanPostProcessor() { |
|
22 |
|
|
23 |
@Override |
|
24 |
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { |
|
25 |
if (!(bean instanceof ThreadPoolTaskExecutor)) { |
|
26 |
return bean; |
|
27 |
} |
|
28 |
// 修改提交的任务,接入 TransmittableThreadLocal |
|
29 |
ThreadPoolTaskExecutor executor = (ThreadPoolTaskExecutor) bean; |
|
30 |
executor.setTaskDecorator(TtlRunnable::get); |
|
31 |
return executor; |
|
32 |
} |
|
33 |
|
|
34 |
}; |
|
35 |
} |
|
36 |
|
|
37 |
} |