A CompletableFutureis not what acts, so I'm not sure what you mean by
which create 10 terminating futures
I assume that you set the task with runAsyncor submitAsync. My example will not be, but the behavior will be the same if you do.
root CompletableFuture. , ( Executor, runAsync Thread CompletableFuture ). 10 CompletableFuture CompletableFuture#allOf, CompletableFuture, , ( ), thenRun, .
public static void main(String args[]) throws Exception {
CompletableFuture<String> root = new CompletableFuture<>();
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.submit(() -> {
CompletableFuture<String> cf1 = CompletableFuture.completedFuture("first");
CompletableFuture<String> cf2 = CompletableFuture.completedFuture("second");
System.out.println("running");
CompletableFuture.allOf(cf1, cf2).thenRun(() -> root.complete("some value"));
});
root.thenAccept(r -> {
System.out.println(r);
});
Thread.sleep(100);
executor.shutdown();
}