supplyAsync
The CompletableFuture method that starts a task producing a value on another thread and returns a future for it.
In more detail
Without an executor argument it runs on the common pool, which suits short computations but not blocking I/O. Pass your own executor for work that waits on a database or network.
Example
CompletableFuture.supplyAsync(() -> "ready")Related terms
- CompletableFuture — A Future that can be completed later and chained, letting you describe asynchronous steps such as transform, combine and recover without nesting callbacks.
- Supplier — A functional interface whose get method takes no arguments and returns a value, used to produce something on demand.
- common pool — The JVM-wide shared thread pool that parallel streams and CompletableFuture use by default when you do not supply an executor.
Taught in
- Async With CompletableFuture — Modern Java: Virtual Threads & High-Throughput Services