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 aShutdownManagerobject and have it register ashutdown()hook. Your application objects add themselves to theShutdownManagerwhich can then call some application object shutdown method, either using a trait or through a function object.