- 建立普通的mbeanserver : MBeanServerFactory.createMBeanServer()
- 建立一个平台相关的mbeanserver: ManagementFactory.getPlatformMBeanServer();
- 建立与mbeanserver连接 方式:(不包括本地 pid方式)
- 使用 url ,e.g. service:jmx:rmi://localhost/jndi/rmi://localhost:1099/abc
- 使用 ip:port, 它将翻译成? service:jmx:rmi://localhost/jndi/rmi://ip:port/jmxrmi
- 下面是一个code启动平台mbeanserver的例子
System.setProperty("com.sun.management.jmxremote.authenticate",
"false");
System.setProperty("com.sun.management.jmxremote.ssl", "false");
System.setProperty("java.rmi.server.hostname", "localhost");
// MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer();
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
int registryPort = Registry.REGISTRY_PORT;
LocateRegistry.createRegistry(registryPort);
String jndiPath = "/jmxrmi";
JMXServiceURL url = new JMXServiceURL(
"service:jmx:rmi://localhost/jndi/rmi://localhost:"
+ registryPort + jndiPath);
JMXConnectorServer connectorServer = JMXConnectorServerFactory
.newJMXConnectorServer(url, null, mbeanServer);
connectorServer.start();