@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线程池中
标签:异步,myAsyncThread,线程,executor,ThreadPoolTaskExecutor,public From: https://www.cnblogs.com/xiamingqing/p/17999225