Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

preload all the classes your hook needs with either:

Class.forName("YourObject") or Class clasz = YourObject.class

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top