我正在 Netbeans 中开发一个 java Web 应用程序。现在我想使用 jconsole 监控我的应用程序。
public static void main(String[] args) throws Exception {
String name="Example";
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName object = new ObjectName("org.javalobby.tnt.jmx:type=example");
mbs.registerMBean(name, object);
}
我还将以下行添加到 glassfish:
-Djava.rmi.server.hostname=myhost
-Dcom.sun.management.jmxremote.port=8686
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
问题是我的 bean 没有出现在 JConsole 上。我做错了什么?
最佳答案
您正在将字符串对象作为 MBean 对象传递。关注documentation如下。 使用这个blog link创建示例测试 mbean。
"An MBean is a managed Java object, similar to a JavaBeanTM, that follows the design patterns set forth in the instrumentation level of the JMX specification. An MBean can represent a device, an application, or any resource that needs to be managed. MBeans expose a management interface: a set of readable and/or writable attributes and a set of invokable operations, along with a self-description.
A standard MBean is defined by writing a Java interface called SomethingMBean and a Java class called Something that implements that interface. Every method in the interface defines either an attribute or an operation in the MBean. By default every method defines an operation. Attributes and operations are simply methods which follow certain design patterns. A standard MBean is composed of the MBean interface which lists the methods for all exposed attributes and operations, and the class which implements this interface and provides the functionality of the instrumented resource."
关于java - MBean 未出现在 JConsole 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27620894/