non-blocking
To avoid blocking, use asynchronous callbacks:
-
thenApply: Transform the result.
future.thenApply(result -> result.toUpperCase()) .thenAccept(System.out::println); // Output: HELLO, COMPLETABLEFUTURE!
-
thenAccept: Consume the result (no transformation).
future.thenAccept(result -> System.out.println("Result: " + result));
-
thenRun: Run a task after completion (doesn’t consume the result).
future.thenRun(() -> System.out.println("Computation finished!"));
Backlinks