@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异步执行方法,不要和同步调用方法,写在同一个类中,否则异步执行将失效。
Constructor and Description |
---|
AsyncConfig() |
Modifier and Type | Method and Description |
---|---|
Executor |
getAsyncExecutor()
异步线程池
实现AsyncConfigurer接口并重写getAsyncExecutor方法,返回一个ThreadPoolTaskExecutor,这样我们就获得了一个基本线程池TaskExecutor。 |
org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler |
getAsyncUncaughtExceptionHandler()
自定义异常处理类
|
public org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler()
getAsyncUncaughtExceptionHandler
in interface org.springframework.scheduling.annotation.AsyncConfigurer
public Executor getAsyncExecutor()
getAsyncExecutor
in interface org.springframework.scheduling.annotation.AsyncConfigurer
Copyright © 2022 Pivotal Software, Inc.. All rights reserved.