springboot 开启@Async异步注解配置默认线程池

springboot 开启@Async异步注解配置默认线程池,第1张

继承org.springframework.scheduling.annotation.AsyncConfigurer 重写其getAsyncExecutor方法,从而实现@Async默认线程池的配置

@Slf4j
@EnableAsync
@Configuration
@RequiredArgsConstructor
public class AsyncConfig implements AsyncConfigurer {

    private final ExecutorService threadPoolExecutor;

    @Override
    public Executor getAsyncExecutor() {
        return threadPoolExecutor;
    }

    @Override
    public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
        return (arg0, arg1, arg2) -> {
            log.error("Async uncaught exception,throwable:{},method:{},params:{}", arg0,arg1,arg2);
        };
    }

}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/724765.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-26
下一篇 2022-04-26

发表评论

登录后才能评论

评论列表(0条)

保存