爷的眼睛闪亮
insideDotNet En_summerGarden
 BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<>(10);
        ThreadPoolExecutor threadPool = new ThreadPoolExecutor(2, 3, 3, TimeUnit.SECONDS, workQueue, r -> new Thread(r, "sync_export_pool_" + r.hashCode()), (r, executor) -> log.error("队列已满拒绝执行"));
        //异步调用,设置子线程共享
        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        //设置子线程共享
        RequestContextHolder.setRequestAttributes(servletRequestAttributes, true);
        threadPool.submit(() -> {
        //do something
           log.info("当前线程:{}",Thread.currentThread().getName());
        });
        threadPool.shutdown();    

 

posted on 2022-07-12 15:55  爷的眼睛闪亮  阅读(55)  评论(0编辑  收藏  举报