我正在使用 <jmxConfigurator/>
logback 中的元素; 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/>
?
最佳答案
是的,它确实。这是调试器的证明:
但是,有一些限制:
<shutdownHook/>
仅从 1.1.3 版开始可用 <shutdownHook/>
足够了,你必须指定 class
属性(property):<shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook"/>
否则 logback 会提示: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>
然后在日志的末尾,您会看到:
ch.qos.logback.core.hook.DelayingShutdownHook@1a246fc6 中的信息 - 通过关闭 Hook 关闭 Logback 上下文
ch.qos.logback.classic.jmx.JMXConfigurator(default) 中的信息 - onReset() 方法称为 JMXActivator [ch.qos.logback.classic:Name=default,Type=ch.qos.logback.classic.jmx.JMXConfigurator]
关于jmx - logback 的 shutdownHook 是否取消注册 jmxConfigurator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30173249/