异步线程池

@Configuration

@EnableAsync

public class AppConfig implements AsyncConfigurer {

 

@Bean("myAsyncThread”) 

public Executor getAsyncExecutor() {

ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();

executor.setCorePoolSize(10);

executor.setMaxPoolSize(50);

executor.setThreadNamePrefix("myAsyncThread-");

executor.initialize(); return executor; }

}

 

 

在使用的地方 @Async("myAsyncThread")  则被注释的方法会被异步执行 且是执行在上面的executor线程池中

posted @ 2024-01-31 14:39  清明雨下  阅读(13)  评论(0)    收藏  举报