I have a multithreaded Scala application and I have a shutdown hook that calls a shutdown() method on an object. Unfortunately this doesn't seem to be reliable. Many times it fails to handle SIGINT and throws a NoClassDefFoundError on an anonymous function.
How do I make this shutdown handler more robust?
One suggestion: Rather than registering shutdown()
hook directly, create a ShutdownManager
object and have it register a shutdown()
hook. Your application objects add themselves to the ShutdownManager
which can then call some application object shutdown method, either using a trait or through a function object.