除了 Scala 提供的 future 执行上下文之外:
import scala.concurrent.ExecutionContext.Implicits.global
Play 提供了另一个执行上下文:
import play.api.libs.concurrent.Execution.Implicits.defaultContext
何时在 Play for Scala 中使用每个选项?
最佳答案
您可以在这里找到答案:
Play's internal execution context
这个问题并不完全重复,但非常接近,那里的答案也涵盖了您的问题。
简而言之:
您不得在 Play 中使用import scala.concurrent.ExecutionContext.Implicits.global
。
回复评论
引用答案:
Instead, you would use
play.api.libs.concurrent.Execution.Implicits.defaultContext
, which uses anActorSystem
.
scala.concurrent.ExecutionContext.Implicits.global
is anExecutionContext
defined in the Scala standard library. It is a specialForkJoinPool
that using the blocking method to handle potentially blocking code in order to spawn new threads in the pool. You really shouldn't use this in a Play application, as Play will have no control over it. It also has the potential to spawn a lot of threads and use a ton of memory, if you're not careful.
关于scala - 定义 Play for Scala 中的 future 隐式上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43065793/