@Bean("taskModuleExecutor")
Executor getCrawler1(){
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
threadPoolTaskExecutor.setCorePoolSize(3);
threadPoolTaskExecutor.setMaxPoolSize(10);
threadPoolTaskExecutor.setQueueCapacity(200);
threadPoolTaskExecutor.setThreadNamePrefix("task-concurrent-work");
// threadPoolTaskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
threadPoolTaskExecutor.initialize();
return threadPoolTaskExecutor;
}
@Async("taskModuleExecutor")
public void asyncTest(){
//加上Async表示基于主线程,新开一个线程。
单元测试中遇到主线程完成,但是子线程没有完成,会被中断,服务发布启动不会有这种情况,验证测试可以注释掉@Async("taskModuleExecutor"),看子线程是否会被中断
}
@EnableAsync
public class ServiceBootstrap(){
}