多线程代码

//多线程处理
List<CompletableFuture> futures = new ArrayList<>();

for (InventoryBalanceBatchDto dto: asynchronous) {
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {

try {
TransferOutDataDto transferOutDataDto = new TransferOutDataDto();
transferOutDataDto.setMatkle(dto.getMatkle());
transferOutDataDto.setWerks(dto.getWerks());
transferOutDataDto.setVstel(dto.getVstel());
transferOutDataDto.setChan(dto.getOutChan());
transferOutDataDto.setTargetChan(dto.getTransferChan());
transferOutDataDto.setZrNum(dto.getOutQuantity());
transferOutDataDto.setBalance("1");
transferOutDataDto.setUseOnlyPlInv(dto.getUseOnlyPlInv());
transferOutDataDto.setUseOnlySjInv(dto.getUseOnlySjInv());
transferOutDataDto.setPlInvTransferOrder(dto.getPlInvTransferOrder());
transferOutDataDto.setUserName(name);
iInventoryInvSynRpcService.transferOutOperation(transferOutDataDto);
this.cacheResultSet(dto,"成功");
} catch (Exception e) {
//dto.setErrMsg(e.getMessage());
e.printStackTrace();
this.cacheResultSet(dto,e.getMessage());
}

},CommandContextUtils.getExecutor());

futures.add(future);
}

//多线程执行
for (CompletableFuture<Boolean> future: futures) {
try {
future.get();
} catch (Exception e) {
e.printStackTrace();
}
}
posted @ 2022-06-28 10:59  一颗树丶  阅读(113)  评论(0)    收藏  举报