Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does logback's shutdownHook unregister the jmxConfigurator

Tags:

logback

jmx

I am making use of the <jmxConfigurator/> element in logback; The jmxConfigurator states the following:

Thus, unless your application is a standalone Java application, you **MUST** unregister the JMXConfigurator instance from the JVM's Mbeans server.

The logback documentation also mentions a <shutdownHook/> configuration element which according to the documentation does the following:

Installing a JVM shutdown hook is a convenient way for shutting down logback and releasing associated resources.

Does including the <shutdownHook/> element take care of unregistering the <jmxConfigurator/>?

like image 735
mjj1409 Avatar asked Feb 10 '23 04:02

mjj1409


1 Answers

Yes, it does. Here is a proof from the debugger: enter image description here

However, there are a few restrictions:

  1. <shutdownHook/> is available only as of version 1.1.3
  2. although the documentation says that plain <shutdownHook/> is enough, you have to specify the class property: <shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook"/> otherwise logback complains with:
    ERROR in ch.qos.logback.core.joran.action.ShutdownHookAction - Missing class name for shutdown hook. Near [shutdownHook] line 16
    

To make sure that the JMXConfigurator gets stopped enable debug mode on the logback configuration:

<configuration debug="true">
   ...
</configuration>

Then at the end of your logs you'll see:

INFO in ch.qos.logback.core.hook.DelayingShutdownHook@1a246fc6 - Logback context being closed via shutdown hook
INFO in ch.qos.logback.classic.jmx.JMXConfigurator(default) - onReset() method called JMXActivator [ch.qos.logback.classic:Name=default,Type=ch.qos.logback.classic.jmx.JMXConfigurator]
like image 96
Lukasz Wiktor Avatar answered May 14 '23 20:05

Lukasz Wiktor