logback的shutdownHook是否取消注册jmxConfigurator

时间:2015-05-11 16:46:47

标签: jmx logback

我在logback中使用<jmxConfigurator/>元素; jmxConfigurator声明如下:

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

logback文档还提到了<shutdownHook/>配置元素,根据文档执行以下操作:

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

包含<shutdownHook/>元素是否需要取消注册<jmxConfigurator/>

1 个答案:

答案 0 :(得分:8)

是的,确实如此。以下是调试器的证明: enter image description here

但是,有一些限制:

  1. <shutdownHook/>仅适用于版本1.1.3
  2. 虽然普通<shutdownHook/> the documentation says已足够,但您必须指定class属性: <shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook"/> 否则后退抱怨:
    ERROR in ch.qos.logback.core.joran.action.ShutdownHookAction - Missing class name for shutdown hook. Near [shutdownHook] line 16
    
  3. 要确保JMXConfigurator停止,请在logback配置上启用调试模式:

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

    然后在日志结束时,您会看到:

    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]