Tip: Disable log4j 2’s shutdown handler

At the moment I develop at tyntec an java application that should run as a daemon process on a server to process files and send the result to a remote data sink.

One crucial part of this application is the shutdown. Currently running file processing tasks must run to the end. Queued ones should be canceled.

Additional the shut down of the transfer part of the application must be executed after the last running processing task has finished.

Both requirements are handled by a ShutdownHandler, so this is fine. This handler is registered on the Runtime class of java as a shutdown hook.

The problem

Today I discovered a strange behavior in the log files. Expected is, that the complete shutdown process is logged, like this

But only the first, or nothing was stated in the logfiles.

Sidenote : The tool shuts down properly

After an hour of searching, I figured out, that the problem comes from a registered shutdown hook by Log4j2. The only question left, was: Can I disable the shutdown hook registration?. And the answer is: Yes, really easy!

The solution

Specify the property shutdownHook  with the value disabled . For example the log4j2.xml file would look like:


21 Kudos

One thought on “Tip: Disable log4j 2’s shutdown handler

Leave a Reply

Your email address will not be published. Required fields are marked *