CompletableFuture简单使用

开四个线程,异步+并行地从远端获取结果,然后解析,放入集合

List<Integer> priceList = new ArrayList(4);

CompletableFuture.supplyAsync(() -> this.getPriceFromRemote()).thenAccept(result -> priceList.add(this.parsePrice(result)));
CompletableFuture.supplyAsync(() -> this.getPriceFromRemote()).thenAccept(result -> priceList.add(this.parsePrice(result)));
CompletableFuture.supplyAsync(() -> this.getPriceFromRemote()).thenAccept(result -> priceList.add(this.parsePrice(result)));
CompletableFuture.supplyAsync(() -> this.getPriceFromRemote()).thenAccept(result -> priceList.add(this.parsePrice(result)));
原文地址:https://www.cnblogs.com/JaxYoun/p/14264708.html