5

Stop an Akka actor system from an actor

 3 years ago
source link: https://www.codesd.com/item/stop-an-akka-actor-system-from-an-actor.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Stop an Akka actor system from an actor

advertisements

I know I can use system.shutdown() outside of an actor system to stop the actor system and make system.awaitTermination() stop blocking execution on its thread.

I want to trigger the actor system shutdown from within one of my Actors. I thought I should be able to call context.system.shutdown() from within an Actor's receive method, however when I do this nothing seems to happen, system.awaitTermination() (on the main thread) just keeps on blocking.

Any ideas?


You should not do that: it is like a snake biting its own tail.

system.awaitTermination() will keep blocking because you are precisely waiting for it to end!

You can perfectly call context.system.shutdown() within an actor, but you cannot call system.awaitTermination() in the actor system context. And also it does not make a lot of sense: why would you wait since there is anyway nothing to execute afterwards, the system being down?

Blocking on the system to shut down makes sense outside of it only, if you want to execute further instructions after it has been stopped.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK