shekhargulati / 52-technologies-in-2016

Let's learn a new technology every week. A new technology blog every Sunday in 2016.
https://shekhargulati.com/
MIT License
7.19k stars 597 forks source link

Week 38: Actor System Termination on JVM Shutdown #57

Open shekhargulati opened 7 years ago

shekhargulati commented 7 years ago

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

jotomo commented 7 years ago

Line 145: This meantApp1ControlActorcan successfully does not have to wait for JVM to exit.

Missing shut down and between successfully and does not

shekhargulati commented 7 years ago

@jotomo thanks. I have incorporated the feedback.

bszwej commented 7 years ago

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