Skip to content

Instantly share code, notes, and snippets.

@hisui
Last active September 11, 2017 14:21
Show Gist options
  • Save hisui/b0af844d131c138760c8ff079e4e00a7 to your computer and use it in GitHub Desktop.
Save hisui/b0af844d131c138760c8ff079e4e00a7 to your computer and use it in GitHub Desktop.
def waitForSIGTERM(cv: AnyRef = new Object()) {
Runtime.getRuntime.addShutdownHook(
new Thread(() => cv.synchronized(cv.notify()))
)
@tailrec
def loop(): Unit = try cv.synchronized(cv.wait())
catch {
case _: InterruptedException => loop()
}
loop()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment