52-technologies-in-2016 icon indicating copy to clipboard operation
52-technologies-in-2016 copied to clipboard

Week 38: Actor System Termination on JVM Shutdown

Open shekhargulati opened this issue 7 years ago • 3 comments

Please provide your feedback by posting a comment against this issue.

shekhargulati avatar Sep 20 '16 20:09 shekhargulati

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 avatar Sep 23 '16 22:09 jotomo

@jotomo thanks. I have incorporated the feedback.

shekhargulati avatar Sep 24 '16 07:09 shekhargulati

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) ;).

bszwej avatar Oct 16 '16 14:10 bszwej