我在努力学习am阿克卡的监督策略。当我在下面有这样的代码时,我确实得到了这个
java.lang.ArithmeticException: /零
case object CreateChildren
case class DivideNumbers(n: Int , d:Int)
object SuperVision extends App {
val actorSystem = ActorSystem("SupervisingActorSystem")
val actor = actorSystem.actorOf(Props[ParentActor], "ParentActor")
actor ! CreateChildren
val child1 = actorSystem.actorSelection("/user/ParentActor/childActor")
child1 ! DivideNumbers(4,0)
class ParentActor extends Actor{
override def receive: Receive = {
case CreateChildren =>
context.actorOf(Props[ChildActor], "childActor")
}
}
class ChildActor extends Actor{
override def receive: Receive = {
case DivideNumbers(n,d) => println(n/d)
}
}
actorSystem.terminate()
}
但是,当我没有儿童演员创造,并有这样的东西,我没有看到例外。
val actorSystem = ActorSystem("SupervisingActorSystem")
val actor = actorSystem.actorOf(Props[ParentActor], "ParentActor")
actor ! DivideNumbers(4, 2)
class ParentActor extends Actor {
override def receive: Receive = {
case DivideNumbers(n, d) => println(n / d)
//case DivideNumbers(n, d) => throw new Exception
//Even this doesn't throw an exception
}
}
actorSystem.terminate()
发布于 2019-01-17 02:21:32
您没有得到该异常仅仅是因为在异常引发之前,您的参与者系统已被终止,然后应用程序退出。
尝试在Thread.sleep(1000)
之前添加actorSystem.terminate()
,您将看到异常。
顺便说一句:这种行为与if you use only one actor or with a child
无关。如果您使用一个子程序,仅仅因为它是一个与时间序列相关的随机行为,就会得到异常。
https://stackoverflow.com/questions/54227963
复制相似问题