title: Why does a supervisor restart its children after overriding the supervisor's preRestart hook to have it refrain from stopping its children in akka?
body: <p>I am reading a tutorial about akka's fault tolerance at  <a href="http://doc.akka.io/docs/akka/current/scala/fault-tolerance.html" rel="nofollow noreferrer">http://doc.akka.io/docs/akka/current/scala/fault-tolerance.html</a>. The code snippets and texts at the end of the article shows that if the supervisorStrategy for Exception in Supervior is Esclate then the Supervisor would escalte the Exception thrown in its children to its supervisor causing the Supervisor to restart and to stop all its children. I can link the "To stop all the children" action to source code from Actor.scala from Akka source code and understand this behavior.</p>
  
  <pre><code>  def preRestart(reason: Throwable, message: Option[Any]): Unit = {
      context.children foreach { child ⇒
        context.unwatch(child)
        context.stop(child)
      }
      postStop()
    }
  </code></pre>
  
  <p>The article then introduces Supervisor2 which differs Supervisor's in that  a preRestart method with no operation is added. Then Supervisor2's children would survive in the case of Exception as Supervisor2 does nothing in the preRestart hook instead of iterating its children and halting each of them. However the children get restarted and lose its state as below code shows.</p>
  
  <pre><code>child3 ! new Exception("CRASH")
  child3 ! "get"
  expectMsg(0) // lose its state
  </code></pre>
  
  <p>I use breakpoint in my IDE to confirm the restart of the child do exist and the preRestart is called for the child.</p>
  
  <p>My question is I cannot figure out when and why the child gets restarted. Can you shed light on this? Is there any principal or source code that I can refer to to understand this behavior?</p>