CompletableFuture的使用
2024-10-20 04:06:49
1 List<List<String>> subList = CommonUtils.splitList(pendingIds, 500);
private static final ThreadFactory NAMED_THREAD_FACTORY =
2 new ThreadFactoryBuilder().setNameFormat("syncContractLine-pool-%d").build();
3 ThreadPoolExecutor threadPool = new ThreadPoolExecutor(10, 20, 500, TimeUnit.MILLISECONDS,
4 new LinkedBlockingQueue<>(500), NAMED_THREAD_FACTORY, new ThreadPoolExecutor.AbortPolicy());
5 IRequestContext current = RequestContextManager.getCurrent();
6 List<CompletableFuture<Void>> futureList = new ArrayList<>();
7 for (List<String> subPendingIds : subList) {
8 CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
9 RequestContextManager.setCurrent(current);
10 LOGGER.info("handle contractLines start");
11 if (CommonUtils.isNotEmpty(subPendingIds)) {
12 for (String id : subPendingIds) {
13 map.put("contract", id);
14 iContractHeaderInfoService.syncContractLineInfo(map);
15 }
16 }
17 LOGGER.info("handle contractLines end");
18 }, threadPool);
19 futureList.add(future);
20 }
21 CompletableFuture.allOf(futureList.toArray(new CompletableFuture[futureList.size()])).join();
22 threadPool.shutdown();
最新文章
- 1.3 jQuery基础
- putty如何使用
- Eclipse导出可执行Java工程/可执行Jar文件(包含第三方Jar包)
- BZOJ1565: [NOI2009]植物大战僵尸
- 虚析构函数(√)、纯虚析构函数(√)、虚构造函数(X)
- 10个你能参与并学习的Java开源项目
- phpMyAdmin import.php 跨站脚本漏洞
- SPOJ 1043 1043. Can you answer these queries I
- XmlDocument加载有Xmlns的xml文档,使用Xpath
- BZOJ 1708: [Usaco2007 Oct]Money奶牛的硬币
- There was a problem parsing the package(android)
- appium python ios 自动化
- ngRx 官方示例分析 - 3. reducers
- C# 值类型与引用类型的异同
- 数据合并处理concat
- python头部 #!/usr/bin/env python
- Ruby 集合数组常用遍历方法
- maven plugins
- php and mysql 常用api函数
- Nginx的几个常用配置和技巧