爷的眼睛闪亮
insideDotNet En_summerGarden
随笔 - 670,  文章 - 0,  评论 - 53,  阅读 - 191万
复制代码
 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   爷的眼睛闪亮  阅读(60)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
历史上的今天:
2017-07-12 使用Maven构建多模块项目

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示