On this page
CompletableFuture
Prev: `ExecutorService` | Up: java.util.concurrent | Next: `ConcurrentHashMap`
Rel: java.util.concurrent, java/builtins
Ref: Java Docs — CompletableFuture
Tags: #public #prog #java #stdlib #java_util_concurrent #tier/core
Import
import java.util.concurrent.*;
Signature & Overview
CompletableFuture.supplyAsync(...).thenApply(...)
Composable asynchronous future supporting .thenCompose(), .allOf(), .orTimeout(), and .exceptionally().
Notes & Pitfalls
- Always pass a custom
Executorfor blocking I/O: DefaultsupplyAsync()runs on the sharedForkJoinPool.commonPool().
Example
import java.util.concurrent.CompletableFuture;
var f = CompletableFuture.supplyAsync(() -> 21).thenApply(n -> n * 2);
assert f.join() == 42;
Linked from
Related notes
- tuts/java/stdlib/java_util_concurrent/ConcurrentHashMap Linked here; links to this page; shared tags: #java, #prog, #stdlib, #tier
- tuts/java/stdlib/java_util_concurrent/ExecutorService Linked here; links to this page; shared tags: #java, #prog, #stdlib, #tier
- tuts/java/stdlib/java_util_concurrent Linked here; links to this page; shared tags: #java, #prog, #stdlib
- tuts/java/builtins Linked here; shared tags: #java, #prog
- tuts/java/stdlib/java_net_http/HttpClient shared tags: #java, #prog, #stdlib, #tier
- tuts/java/stdlib/java_net_http/HttpRequest shared tags: #java, #prog, #stdlib, #tier
- tuts/java/stdlib/java_net_http/HttpResponse shared tags: #java, #prog, #stdlib, #tier
- tuts/java/stdlib/java_nio_and_io/BufferedReader shared tags: #java, #prog, #stdlib, #tier
- tuts/java/stdlib/java_nio_and_io/Files shared tags: #java, #prog, #stdlib, #tier
- tuts/java/stdlib/java_nio_and_io/Path shared tags: #java, #prog, #stdlib, #tier