One way of stopping actors is by calling the stop method from the system or context for a particular actor. To do this, we can define a particular message that can be passed to the actor, telling it to stop. For example:
case "terminate" => context stop self
Most of the times the preferred way of terminating an actor is by sending a PoisonPill message to it:
simpleActor ! PoisonPill
This simple message passing can terminate the actor gracefully. The termination takes place after all the messages in the Actor's queue are processed before the poison pill is processed. Stopping an actor stops all of its child actors. Remember, we talked about those hook methods that can be called if we want to perform some logic when the actor is starting up or at termination. Let's take a look at those.