scala - 定义 Play for Scala 中的 future 隐式上下文

标签 scala playframework

除了 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 an ActorSystem.

scala.concurrent.ExecutionContext.Implicits.global is an ExecutionContext defined in the Scala standard library. It is a special ForkJoinPool 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/

相关文章:

scala - 使用类型类时,如何以不同的方式处理对象?

scala - 类型安全激活器编译错误

scala - < :< and <: in scala 之间有什么不同

scala - Firebase 和 Play Framework (Scala) 有可能吗?

database - 在 Play 框架中使用数据库

playframework - 关于事务和嵌套数据库写入(使用 Scala)

javascript - 如何在play框架中为不同的 View 页面指定不同的JS文件?

java - 在混合 Scala 和 Java Spark 项目中使用 Java 类类型的自定义累加器 Spark 错误

scala - 为什么 Doobie 使用免费 monad?

playframework - Play Framework 2 : Eclipse cant detect jBCrypt as project dependency