在this section of the documentation中,他们解释了如何为scala
Future {
// Some blocking or expensive code here
}(myExecutionContext)
当您使用CompletableFuture
:
CompletableFuture.supplyAsync(() -> {
// Some blocking or expensive code here
}, someCustomExecutor);
使用java
和CompletableFuture
时,我们如何确保上下文可用?
答案 0 :(得分:2)
CompletableFuture.supplyAsync(() -> {
// Some blocking or expensive code here
}, play.libs.concurrent.HttpExecution.defaultContext());
来自the docs:
ExecutionContexts保存当前线程的上下文ClassLoader和Http.Context。