shekhargulati / 52-technologies-in-2016

Let's learn a new technology every week. A new technology blog every Sunday in 2016.

Home Page:https://shekhargulati.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Week 38: Actor System Termination on JVM Shutdown

shekhargulati opened this issue · comments

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