private List<JSONObject> asyncGet(List<BO> list)
throws Exception {
List<JSONObject> objectList = new ArrayList<>();
CompletableFuture[] futures = list.stream()
.map(p -> CompletableFuture.supplyAsync(() -> get需要远程调用的接口(接口参数))
).toArray(CompletableFuture[]::new);
CompletableFuture<Void> completableFuture = CompletableFuture.allOf(futures);
completableFuture.get(3000, TimeUnit.MILLISECONDS);
for (CompletableFuture future:futures) {
objectList.add((JSONObject)future.get());
}
return objectList;
}
批量获取实现方式list
版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。