Termination of an actor proceeds in two steps: first the actor suspends its mailbox processing and sends a stop command to all its children, then it keeps processing the termination messages from its children until the last one is gone, finally terminating itself (invoking postStop, dumping mailbox, publishing Terminated on the DeathWatch, telling its supervisor). This procedure ensures that actor system sub-trees terminate in an orderly fashion, propagating the stop command to the leaves and collecting their confirmation back to the stopped supervisor. If one of the actors does not respond (i.e. processing a message for extended periods of time and therefore not receiving the stop command), this whole process will be stuck.
scala> val system = ActorSystem("system")system: akka.actor.ActorSystem = akka://systemscala> class ActorB extends Actor { def receive ={ case _ =>} ; override def postStop() { println("postStop B") } }defined class ActorBscala> class ActorA extends Actor { val actorB = context.actorOf(Props[ActorB]) ; context.watch(actorB) ; def receive = { case Terminated(actor) => println("supervised terminated :"+ actor) } ; override def postStop() { println("postStop A") } }defined class ActorAscala> val actorA = system.actorOf(Props(classOf[ActorA]))actorA: akka.actor.ActorRef = Actor[akka://system/user/$a#-1326401100]scala> system.registerOnTermination(println("System shutdown"))scala> system.shutdown()scala> postStop BpostStop ASystem shutdown
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://akka.io/faq/
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/groups/opt_out.
Patrik Nordwall
Typesafe - The software stack for applications that scale
Twitter: @patriknw
Termination of an actor proceeds in two steps: first the actor suspends its mailbox processing and sends a stop command to all its children, then it keeps processing the termination messages from its children until the last one is gone, finally terminating itself (invoking postStop, dumping mailbox, publishing Terminated on the DeathWatch, telling its supervisor).
Hi,Can you clarify what this sentence from the documentation means:Termination of an actor proceeds in two steps: first the actor suspends its mailbox processing and sends a stop command to all its children, then it keeps processing the termination messages from its children until the last one is gone, finally terminating itself (invoking postStop, dumping mailbox, publishing Terminated on the DeathWatch, telling its supervisor).Is this incorrect? How does an actor process the termination messages from its children, other than through receiving Terminated messages in its mailbox?
it keeps processing the termination messages from its children until the last one is gone