斯卡拉 – 阿卡调度员的继承权
发布时间:2020-12-16 09:00:49 所属栏目:安全 来源:网络整理
导读:我正在和Akka一起工作,我们仍然要相互了解. 我的方案是:我为主管(父)演员选择了一个非默认调度员,他的角色是管理(监督)并创建子演员来完成工作. 问题:儿童演员是否继承了父母的演员? 我知道您可以为配置中指定的父actor的子actor明确指定一个不同的调度程
我正在和Akka一起工作,我们仍然要相互了解.
我的方案是:我为主管(父)演员选择了一个非默认调度员,他的角色是管理(监督)并创建子演员来完成工作. 问题:儿童演员是否继承了父母的演员? 我知道您可以为配置中指定的父actor的子actor明确指定一个不同的调度程序. akka.actor.deployment { /my-parent-actor { dispatcher = dispatcher-for-parent } "/my-parent-actor/*" { dispatcher = dispatcher-for-children } } 我的问题是,如果您指定父actor调度程序,而没有明确指定子actor的调度程序,是否继承父项actor的子项. 解决方法
从我所看到的,默认情况下,孩子不会继承父母的主管.我无法在任何地方的文档中明确地找到它,所以我写了一段快速代码来验证我的初始假设:
import com.typesafe.config.ConfigFactory import akka.actor._ object DispatcherTest extends App{ val conf = ConfigFactory.parseString(""" { my-custom-dispatcher { executor = "thread-pool-executor" type = PinnedDispatcher } } """) val system = ActorSystem("test",conf) val supervisor = system.actorOf(Props[MySupervisor].withDispatcher("my-custom-dispatcher")) } class MySupervisor extends Actor{ println(s"I am the supervisor,my dispatcher is: ${context.dispatcher}") val child = context.actorOf(Props[MyChild]) def receive = { case _ => } } class MyChild extends Actor{ println(s"I am the child,my dispatcher is: ${context.dispatcher}") def receive = { case _ => } } 如果你运行它,你会看到: I am the supervisor,my dispatcher is: PinnedDispatcher[my-custom-dispatcher] I am the child,my dispatcher is: Dispatcher[akka.actor.default-dispatcher] (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |