Completable Futures - thenApply vs thenCompose
Let’s wrap a blocking operation in a CompletablFuture 1 2 3 4 5 6 7 public static Integer blockingCall(int x) { return x * 2; } public static CompletableFuture<Integer> asyncRunner(int x) { return CompletableFuture.supplyAsync(() -> blockingCall(x)); } Here we chain the outputs so that it prints the aggregated results. But this will print the future not the value (16) 1 2 3 4 5 public static void main(String[] args) { asyncRunner(4) ....