异步线程

2021-01-27 19:12

阅读:450

标签:rap   void   单元   raw   run   current   str   queue   异步线程   

    @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(){
}

异步线程

标签:rap   void   单元   raw   run   current   str   queue   异步线程   

原文地址:https://www.cnblogs.com/meadow/p/12844826.html


评论


亲,登录后才可以留言!