In which thread does CompletableFuture's completion handlers execute in?

前端 未结 4 1465
无人及你
无人及你 2020-11-29 04:59

I have a question about CompletableFuture method:

public  CompletableFuture thenApply(Function fn)

4条回答
  •  暖寄归人
    2020-11-29 05:20

    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().

提交回复
热议问题