zoukankan      html  css  js  c++  java
  • 异步线程

        @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(){
    }
  • 相关阅读:
    最短路
    Codeforces Round #607 (Div. 2) C. Cut and Paste
    第三次训练赛
    训练赛
    day27-反射
    day26-网络编程
    tcp文件上传--多个客户端
    tcp图片上传
    tcp文件上传优化
    tcp文件上传
  • 原文地址:https://www.cnblogs.com/meadow/p/12844826.html
Copyright © 2011-2022 走看看