简体   繁体   English

检索注册的JMX mbean的信息

[英]Retrieve the information of a registered JMX mbean

I am using Eclipse to write two simple Java Programs. 我正在使用Eclipse编写两个简单的Java程序。 The first program creates a simple mbean and register it in an Mbean server. 第一个程序创建一个简单的mbean并将其注册在Mbean服务器中。 The second program retrieves the information of the registered mbean. 第二个程序检索已注册的mbean的信息。 To register and retrieve the mbean I used the code below to create the server for both programs: 要注册和检索mbean,我使用下面的代码为这两个程序创建了服务器:

MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

When I run my second program it doesn't list the created Mbean and the two lines below return false. 当我运行第二个程序时,它不会列出创建的Mbean,并且下面的两行返回false。

ObjectName mbeanName = new ObjectName("HelloAgent:name=helloWorld1");
mbs.isRegistered(mbeanName);

However, I can see it and access it by using JConsole. 但是,我可以使用JConsole看到并访问它。 Have I missed something? 我错过了什么吗? Thank you! 谢谢! jconsole snapshot1 jconsole快照1 jconsole快照1 jconsole snapshot 2 jconsole快照2 jconsole快照2

As you mentioned that you are running two different Java Programs, which means they both have different MBean Server and are running in different JVM. 正如您提到的,您正在运行两个不同的Java程序,这意味着它们都具有不同的MBean Server ,并且在不同的JVM中运行。

mbs.isRegistered(mbeanName);

The above method will check whether the MBean is registered with the MBean server of the current Java process or not. 上面的方法将检查MBean是否已在当前Java进程的MBean服务器中注册。 It cannot query the MBean server of another Java program. 它不能查询另一个Java程序的MBean服务器。

To access the MBean from another Java program, you need to create a client which will query your first Java program(containing the MBean that you want to manage) using RMI. 要从另一个Java程序访问MBean,您需要创建一个客户端,该客户端将使用RMI查询您的第一个Java程序(包含要管理的MBean)。

You may find this tutorial helpful to actually understand how JMX monitoring using MBenas work . 您可能会发现本教程对实际了解使用MBenas进行JMX监视的工作很有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM