其他分享
首页 > 其他分享> > 多线程代码

多线程代码

作者:互联网

//多线程处理
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();
}
}

标签:dto,transferOutDataDto,代码,futures,future,CompletableFuture,多线程
来源: https://www.cnblogs.com/yiheshudian/p/16418752.html