如果代码中的dedicated dispatcher
会自动在application.conf
中查找dispatcher
src/main/resources/application.conf
呢?这里有两个执行上下文的配置示例,您可以将其放入application.conf
中:
background-scheduled-tasks-dispatcher {
type = Dispatcher
executor = "fork-join-executor"
fork-join-executor {
parallelism-min = 2
parallelism-factor = 2.0
parallelism-max = 10
}
throughput = 1
}
blocking-io-ec {
type = Dispatcher
executor = "thread-pool-executor"
thread-pool-executor {
fixed-pool-size = 50
}
throughput = 1
}
下面是一个如何在你的应用程序中访问它们的例子:
val ec :ExecutionContext = actorSystem.dispatchers.lookup("blocking-io-ec")
你可以在行前加上implicit val ec
或者直接使用
someFuture.map(myFunc)(ec)