November 2017
Intermediate to advanced
398 pages
10h 14m
English
Here's how we can chain the same operations using the CompletableFuture API:
stopWatch.start();ExecutorService pool = Executors.newCachedThreadPool();CompletableFuture<String> cf1 = CompletableFuture.supplyAsync(() -> doStageEx(Stage.FoundationMaterials), pool);CompletableFuture<String> cf2 = CompletableFuture.supplyAsync(() -> doStageEx(Stage.WallsMaterials), pool);CompletableFuture<String> cf3 = CompletableFuture.supplyAsync(() -> doStageEx(Stage.RoofMaterials), pool);CompletableFuture.allOf(cf1, cf2, cf3) .thenComposeAsync(result -> CompletableFuture.supplyAsync(() -> SUCCESS), pool) .thenApplyAsync(result -> doStage(Stage.Foundation, result), pool) .thenApplyAsync(result -> doStage(Stage.Walls ...
Read now
Unlock full access