现在的位置: 首页 > 综合 > 正文

jmx获取MBeanServerConnection的两种方法

2013年01月11日 ⁄ 综合 ⁄ 共 982字 ⁄ 字号 评论关闭

jmx获取MBeanServerConnection的方法有两种

method1:

JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://10.1.60.14:6666/osgi");
JMXConnector jmxConnector = JMXConnectorFactory.connect(url);

MBeanServerConnection mbsc = jmxConnector.getMBeanServerConnection();

method2:

Registry registry=LocateRegistry.getRegistry("10.1.60.14",6666);  

RMIServer stub=null;  

       JMXConnector jmxc=null;  
       if (stub == null) {  
stub = (RMIServer) registry.lookup("osgi");

        
       jmxc = new RMIConnector(stub, null);  
       jmxc.connect();  
       MBeanServerConnection mbsc=jmxc.getMBeanServerConnection();

两种方法是通用的,某些特殊应用,API上面意思是最好使用第二种方法,具体原因没有找到。

另外贴一段网上的建议:

f Tomcat is running on JDK 5, and if you want to use RMI over SSL, then you might need to create your RMI Connector Server by hand (rather than going through the JMXConnectorServerFactory), in order to
control the port# and RMI Socket Factories that are used when creating the RMI registry and when exporting the RMIServer object through the RMI registry.
摘自:http://blogs.oracle.com/jmxetc/entry/connecting_through_firewall_using_jmx

抱歉!评论已关闭.