From 81904117741bb7e1249aaa4ccbca1e94fa40c8e9 Mon Sep 17 00:00:00 2001 From: zhanghai <120228220@qq.com> Date: Mon, 3 Jun 2024 15:06:37 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=B9=B6=E5=8F=91=E4=B8=8D?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/docus/demo/service/SyncBasicFileImpl.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/docus/demo/service/SyncBasicFileImpl.java b/src/main/java/com/docus/demo/service/SyncBasicFileImpl.java index ae9163e..312d894 100644 --- a/src/main/java/com/docus/demo/service/SyncBasicFileImpl.java +++ b/src/main/java/com/docus/demo/service/SyncBasicFileImpl.java @@ -42,7 +42,7 @@ public class SyncBasicFileImpl implements ISyncBasicFileService { private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); - private final ExecutorService executor = new ThreadPoolExecutor(3, 3, + private final ExecutorService executor = new ThreadPoolExecutor(5, 10, 30L, TimeUnit.DAYS, new LinkedBlockingQueue()); @@ -71,8 +71,9 @@ public class SyncBasicFileImpl implements ISyncBasicFileService { log.info("查询不到基础数据"); break; } + List> futures = new ArrayList<>(); for (BasicVo basicVo : basicVoList) { - CompletableFuture.runAsync(() -> { + CompletableFuture future = CompletableFuture.runAsync(() -> { try { List cardInfoByCid = pictureMapper.getCardInfoByCid(basicVo.getBColumn5()); if (ObjectUtil.isEmpty(cardInfoByCid)) { @@ -120,8 +121,12 @@ public class SyncBasicFileImpl implements ISyncBasicFileService { }, executor); + futures.add(future); + log.info("本次同步基础数据大小" + basicVoList.size()); + } + for(CompletableFuture future:futures){ + future.join(); } - log.info("本次同步基础数据大小" + basicVoList.size()); } return CommonResult.success("同步成功"); @@ -229,7 +234,7 @@ public class SyncBasicFileImpl implements ISyncBasicFileService { // } // } - ExecutorService executor = new ThreadPoolExecutor(30, 30, + ExecutorService executor = new ThreadPoolExecutor(5, 5, 30L, TimeUnit.DAYS, new LinkedBlockingQueue());