Open PipsqueakH opened 7 years ago
Kill会实际上抛出的是ActorKilledException, 而这个异常在supervisor strategy的Decider是Stop,而不是Restart。
final val defaultDecider: Decider = {
case _: ActorInitializationException ⇒ Stop
case _: ActorKilledException ⇒ Stop
case _: DeathPactException ⇒ Stop
case _: Exception ⇒ Restart
}
如果要模拟Restart,可以在parent中将ActorKilledException的Decider改为Restart
@PipsqueakH 楼上是正解。不过你的需求还挺特殊的,使用actor一般会主动stop,很少见主动restart的。
Akka的文档里有 You can kill an actor by sending a Kill message. This will cause the actor to throw a ActorKilledException, triggering a failure. The actor will suspend operation and its supervisor will be asked how to handle the failure, which may mean resuming the actor, restarting it or terminating it completely.
我想让一个actor给自己发一个Kill消息,然后让parent来restart他
得到的结果是
并没有restart, 如果不用Kill, 而是直接抛出异常确实可以restart的,这是什么原因呢?