Java SE API
CompletableFuture.join()
Wait for the result, using unchecked exceptions for failure or cancellation.
Formal Syntax & Structure
java syntaxjava
T join()Working Example
Example Snippetjava
import java.util.concurrent.*;import java.util.concurrent.atomic.*;import java.util.concurrent.locks.*;public class Main {
public static void main(String[] args) throws Exception { CompletableFuture<Integer> failed = CompletableFuture.failedFuture(new IllegalArgumentException("bad input")); try { failed.join(); } catch (CompletionException e) { System.out.println(e.getCause().getClass().getSimpleName()); } try { failed.get(1, TimeUnit.SECONDS); } catch (ExecutionException e) { System.out.println(e.getCause().getMessage()); } }}