jmx添加naming service以及一个rmi 监听方式

			ObjectName namingName = new ObjectName("naming:type=rmiregistry");
			mx4j.tools.naming.NamingService service = new mx4j.tools.naming.NamingService();
			_mBeanServer.registerMBean(service, namingName);
			_mBeanServer.setAttribute(namingName, new Attribute("Port", new Integer(1984)));
			_mBeanServer.invoke(namingName, "start", null, null);
			//startup the naming service. Just like a dns server.
			int port = ((Integer) _mBeanServer.getAttribute(namingName, "Port")).intValue();

	        // The address of the connector
	        JMXServiceURL address = new JMXServiceURL(
	            "service:jmx:rmi://localhost/jndi/rmi://localhost" + ":" + port + "/jmxconnector");
	        JMXConnectorServer connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(address, null, _mBeanServer);
	        connectorServer.start();
	        // start up the rmi service. Just like a application server, such as http, ftp, smtp server.


jdk1.6对mx4j的一些东西有兼容性问题,需要手动指定:
-Djavax.management.builder.initial=mx4j.server.MX4JMBeanServerBuilder

你可能感兴趣的:(UP)