代碼實作:
List<String> line = new ArrayList();
List<CompletableFuture<>> totalLines = lines.stream()
.map(productLine -> CompletableFuture.supplyAsync(() ->
{
//do something async
}))
.collect(Collectors.toList());
//線程聚合等待
CompletableFuture.allOf(totalLines.toArray(new CompletableFuture[0])).join();