I have a question about CompletableFuture method:
public CompletableFuture thenApply(Function super T, ? extends U> fn)
From the Javadoc:
Actions supplied for dependent completions of non-async methods may be performed by the thread that completes the current CompletableFuture, or by any other caller of a completion method.
More concretely:
fn will run during the call to complete() in the context of whichever thread has called complete().
If complete() has already finished by the time thenApply() is called, fn will be run in the context of the thread calling thenApply().