52-technologies-in-2016
52-technologies-in-2016 copied to clipboard
Week 38: Actor System Termination on JVM Shutdown
trafficstars
Please provide your feedback by posting a comment against this issue.
Line 145: This meant App1ControlActor can successfully does not have to wait for JVM to exit.
Missing shut down and between successfully and does not
@jotomo thanks. I have incorporated the feedback.
Hi,
you could have used sys.addShutdownHook from scala.sys package object which is a nice scala wrapper over java Runtime.getRuntime.addShutdownHook.
So basically instead of this:
Runtime.getRuntime.addShutdownHook(new Thread(new Runnable {
override def run(): Unit = {
val terminate: Future[Terminated] = system.terminate()
Await.result(terminate, Duration("10 seconds"))
}
}))
you can do this:
sys.addShutdownHook {
val terminate: Future[Terminated] = system.terminate()
Await.result(terminate, Duration("10 seconds"))
}
which looks nicer (less boilderplate) ;).