【发布时间】:2015-12-06 12:10:40
【问题描述】:
Scala 执行上下文和调度程序 - 列表和比较:为什么?
关于在 Scala 中使用什么/如何/什么是最好的 Execution Context 以及如何配置调度程序存在很多问题。
我仍然无法找到更长的列表,其中包含优缺点和配置示例。
我能找到的最好的是 Akka 文档:http://doc.akka.io/docs/akka/snapshot/scala/dispatchers.html 和 Play 文档https://www.playframework.com/documentation/2.5.x/ThreadPools。
我想问一下,除了scala.concurrent.ExecutionContext.Implicits.global 和 Akka 默认值之外,您在日常开发生活中还使用了哪些配置,什么时候使用它们,优缺点是什么。
以下是我已经拥有的一些:
第一个未完成的概述
标准:scala.concurrent.ExecutionContext.Implicits.global
不确定时使用
易于使用
- 为所有内容共享
可能会耗尽你所有的 CPU
更多信息:http://www.scala-lang.org/api/2.11.5/index.html#scala.concurrent.ExecutionContext
测试 - ExecutionContext.fromExecutor(new ForkJoinPool(1))
- 用于测试
- 没有并行性
Play 的默认 EC - play.api.libs.concurrent.Execution.Implicits._
- 在使用 Play 时使用
scala.concurrent.ExecutionContext.Implicits.global代替 - 默认播放
共享
更多信息:https://www.playframework.com/documentation/2.5.x/ThreadPools
Akka 的默认执行上下文
隔板
ExecutionContext.fromExecutor(new ForkJoinPool(n)) based on an separated dispatcher . Thanks to Sergiy Prydatchenko
【问题讨论】:
-
ExecutionContext.fromExecutor(new ForkJoinPool(n))(或单独的 Akka 调度程序)不仅可用于测试,还可用于隔板(将Futures的一部分与另一个Executor分开)。
标签: scala concurrency playframework akka spray