解决并发不执行问题

main
zhanghai 1 year ago
parent ecf6f497e9
commit 8190411774

@ -42,7 +42,7 @@ public class SyncBasicFileImpl implements ISyncBasicFileService {
private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); 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, 30L, TimeUnit.DAYS,
new LinkedBlockingQueue<Runnable>()); new LinkedBlockingQueue<Runnable>());
@ -71,8 +71,9 @@ public class SyncBasicFileImpl implements ISyncBasicFileService {
log.info("查询不到基础数据"); log.info("查询不到基础数据");
break; break;
} }
List<CompletableFuture<Void>> futures = new ArrayList<>();
for (BasicVo basicVo : basicVoList) { for (BasicVo basicVo : basicVoList) {
CompletableFuture.runAsync(() -> { CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
try { try {
List<TCardInfo> cardInfoByCid = pictureMapper.getCardInfoByCid(basicVo.getBColumn5()); List<TCardInfo> cardInfoByCid = pictureMapper.getCardInfoByCid(basicVo.getBColumn5());
if (ObjectUtil.isEmpty(cardInfoByCid)) { if (ObjectUtil.isEmpty(cardInfoByCid)) {
@ -120,8 +121,12 @@ public class SyncBasicFileImpl implements ISyncBasicFileService {
}, executor); }, executor);
futures.add(future);
log.info("本次同步基础数据大小" + basicVoList.size());
}
for(CompletableFuture<Void> future:futures){
future.join();
} }
log.info("本次同步基础数据大小" + basicVoList.size());
} }
return CommonResult.success("同步成功"); 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, 30L, TimeUnit.DAYS,
new LinkedBlockingQueue<Runnable>()); new LinkedBlockingQueue<Runnable>());

Loading…
Cancel
Save