Rogach Rogach - 1 year ago 155
Scala Question

How to wait for Akka actor system to terminate?

I need to start Akka (2.0) actor system, send in some messages, then wait for it to do heavy lifting. After that, I need to do something unrelated to those actors.

I tried to wait for all actors to stop with following code:

val system = new ActorSystem("parallelRunners")
val master = system.actorOf(Props[Master])
master ! Start
system.awaitTermination // <-- hangs here

All actors kill themselves via
self ! PoisonPill
. What am I doing wrong?

Answer Source

I found the solution - just call system.shutdown from the master actor:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download