akka中调度程序和执行上下文之间的差异

akka中调度程序和执行上下文之间的差异,akka,Akka,我有以下演员: val actor1 = context.actorOf(SorterActor.build .withDispatcher("akka.actor.custom-dispatcher"), name = "actor_child1") val actor2 = context.actorOf(SorterActor.build .withDispatcher("akka.actor.custom-dispatcher"), name = "actor_child

我有以下演员:

val actor1 = context.actorOf(SorterActor.build
    .withDispatcher("akka.actor.custom-dispatcher"), name = "actor_child1")
val actor2 = context.actorOf(SorterActor.build
    .withDispatcher("akka.actor.custom-dispatcher"), name = "actor_child2")
和执行上下文

implicit val ec: ExecutionContext = context.system.dispatchers.lookup("akka.actor.custom-dispatcher")
我不明白的是,在actor上用
withDispatcher
fn指定要使用的调度程序和指定指向同一调度程序的执行上下文有什么区别。如果执行上下文指向的调度程序与使用
withDispatcher
函数定义的调度程序不同,会发生什么情况


谢谢。

当您在创建参与者时指定一个调度程序时,这些参与者将自己使用该调度程序(用于消息处理)

当您使用执行上下文定义
隐式val
时,它将确定
未来的
-s将在其定义范围内使用哪个执行上下文(当然,您可以显式地将其用于execute
Runnable
-s)

如果隐式执行上下文指向不同的调度程序,而不是使用
withDispatcher
函数定义的调度程序,则您的
Future
-s将在该不同的调度程序上运行(而不是在参与者的调度程序上)。通常,它可用于更细粒度的散装