The default strategy of restarting an actor on failure is not always what we want. In particular, for actors that carry a lot of data, we might want to resume processing after an exception rather than restarting the actor. Akka lets us customize this behavior by setting a supervisor strategy in the actor's supervisor.
Recall that all actors have parents, including the top-level actors, who are children of a special actor called the user guardian. By default, an actor's supervisor is his parent, and it is the supervisor who decides what happens to the actor on failure.
Thus, to change how an actor reacts to failure, you must set its parent's supervisor strategy. You do this by setting the supervisorStrategy
attribute. The default strategy is equivalent to the following:
val supervisorStrategy = OneForOneStrategy() { case _:ActorInitializationException => Stop case _:ActorKilledException => Stop case _:DeathPactException => Stop case _:Exception ...