本文介绍了是否有必要从平台MBean服务器注销MBean?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始使用MBean来公开有关应用程序的一些信息.几乎所有的HOWTOs/教程/博客文章/在线样本都教您如何实现MBean并将其注册到MBean Server,但绝不要提及(或仅是粗略地)从服务器注销MBean.

I've begun playing with MBeans for exposing some information about an app. Pretty much the totality of HOWTOs / Tutorials / Blog posts / Samples online teach you how to implement an MBean and register it with an MBean Server, but never mention (or only cursorily) unregistering the MBean from the server.

我担心一个MBean需要引用相当重的对象才能提供有关该对象的状态信息.

I'm concerned about an MBean that needs to have a reference to a fairly heavyweight object in order to provide status information about that object.

Platform MBean Server是否维护对MBean的弱引用或其他一些技巧,以确保如果您的应用程序不再保留对它的引用,该MBean最终会被GC处理?通常不需要注销,从而解释了为什么在JMX教程中没有人谈论它吗?

Does the Platform MBean Server maintain a weak reference to the MBean, or some other such trick, to ensure that it eventually gets GC'ed if your application no longer holds any references to it? Is unregistering generally unnecessary, thereby explaining why no one is talking about it in JMX tutorials?

推荐答案

您不能(尚未)弱"向服务器注册MBean,从而期望在不存在其他MBean引用时将其GC化.

You can not "weakly" register an MBean with a server (yet), thereby expecting it to be GCed when no other references to it exist.

话虽如此,您绝对应该阅读Eamonn McManus关于该主题的一些帖子.

This being said, you should definitely read some posts by Eamonn McManus on the subject.

https://web.archive.org/web/20120207140653/http://weblogs.java.net/blog/emcmanus/archive/2005/07/cleaning_up_an_1.html

https://web.archive.org/web/20090114131740/http://weblogs.java.net/blog/emcmanus/archive/2005/07/javaone_feedbac.html

打开和关闭昂贵的MBean. 一些MBean可能会导出信息 不断采样, 收集起来很昂贵.你不 一定希望那些MBean是 一直在运行.临时解决方案 很容易,例如 setThreadContentionMonitoringEnabled 方法中 java.lang.management.ThreadMXBean.但 也许会有更一般的 约定,例如 setDetailLevel(int)方法.

Turning on and off expensive MBeans. Some MBeans may export information that is continuously sampled and that is expensive to gather. You don't necessarily want those MBeans to be running all the time. Ad hoc solutions are easy, for instance the setThreadContentionMonitoringEnabled method in java.lang.management.ThreadMXBean. But perhaps there could be a more general convention, such as a setDetailLevel(int) method.

这篇关于是否有必要从平台MBean服务器注销MBean?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-14 19:40