springboot异步执行
使用@EnableAsync开启异步执行
在接口方法上使用@Async注解进行标注,该接口是一个异步接口
自定义异步线程执行器
@Configuration
public class CustomAsyncConfigurer implements AsyncConfigurer {
    @Override
    public Executor getAsyncExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(4);
        executor.setMaxPoolSize(20);
        executor.setQueueCapacity(20);
        executor.setKeepAliveSeconds(60);
        executor.setThreadNamePrefix("myThreadPool-");
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        executor.initialize();
        return executor;
    }
    @Override
    public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
        return new AsyncUncaughtExceptionHandler() {
            @Override
            public void handleUncaughtException(Throwable ex, Method method, Object... params) {
                System.out.println("出现异常");
                ex.printStackTrace();
            }
        };
    }
}
https://zhhll.icu/2021/框架/springboot/基础/8.springboot异步执行/
本文由mdnice多平台发布
   © 
   著作权归作者所有,转载或内容合作请联系作者 
 
 
 
 
喜欢的朋友记得点赞、收藏、关注哦!!!







![[项目详解][boost搜索引擎#1] 概述 | 去标签 | 数据清洗 | scp](https://img-blog.csdnimg.cn/img_convert/da59d787c121e481a9757b8c69fbce71.png)











