Java – JVM shutdown hook quits unexpectedly

JVM shutdown hook quits unexpectedly… here is a solution to the problem.

JVM shutdown hook quits unexpectedly

I’m using a Java agent for JVM analysis of Hadoop tasks like https://github.com/etsy/statsd-jvm-profiler. Analyzer registration closes the hook to save the configuration file to HDFS. But currently the hook is terminated before it is completed. I’m sure they’re executed because I can see some output from the Hook.

Solution

Do you see any IOExceptions or file system shutdown errors. If so, then disabling hdfs to turn off hooks helps.

The HDFS

client also registers a close hook so that the HDFS connection can be closed correctly. The order in which the hooks are closed is not guaranteed. Hdfs hooks may be called before other hooks. You can try disabling the shutdown hook. This also means that you need to close the connection in your code.

Create an HDFS client instance:

Configuration conf = new Configuration();
conf.setBoolean("fs.automatic.close", false);
filesystem = FileSystem.get(nnURI, conf)

In Close Hook:

fileSystem.close();

Related Problems and Solutions