@EnableAsync @Configuration @EnableConfigurationProperties(value=AsyncProperties.class) @ConditionalOnProperty(prefix="yue.thread-pool.async", name="enabled", havingValue="true") public class AsyncConfig extends Object implements org.springframework.scheduling.annotation.AsyncConfigurer
共用父线程上下文环境,异步执行任务时不丢失token
注意,@Async异步执行方法,不要和同步调用方法,写在同一个类中,否则异步执行将失效。
| 构造器和说明 |
|---|
AsyncConfig() |
| 限定符和类型 | 方法和说明 |
|---|---|
Executor |
getAsyncExecutor()
异步线程池
实现AsyncConfigurer接口并重写getAsyncExecutor方法,返回一个ThreadPoolTaskExecutor,这样我们就获得了一个基本线程池TaskExecutor。 |
org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler |
getAsyncUncaughtExceptionHandler()
自定义异常处理类
|
public org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler()
getAsyncUncaughtExceptionHandler 在接口中 org.springframework.scheduling.annotation.AsyncConfigurerpublic Executor getAsyncExecutor()
getAsyncExecutor 在接口中 org.springframework.scheduling.annotation.AsyncConfigurerCopyright © 2019 Pivotal Software, Inc.. All rights reserved.