JMX问题

这个问题貌似是启动tomcat之后就获取不到jmx的链接了,不知咋回事~~
终于找到解决的办法了,呵呵
参考:http://www.docjar.com/html/api/sun/tools/jconsole/ProxyClient.java.html
之前的获取MBeanServerConnection方法看来是有些问题,
以前的方法:

private MBeanServerConnection getRemoteMBConn(){
// String user = "monitorRole";
// String pw = "password";
// String[] credentials = new String[] { user, pw };
// Map<String, String[]> props = new HashMap<String, String[]>();
// props.put("jmx.remote.credentials", credentials);
JMXServiceURL address;
MBeanServerConnection mbs=null;
String jmxServerIp=ConfigUtils.getInstance().getOampConfig(OampConstants.JMX_SERVER_IP);//127.0.0.1
String jmxServerPort=ConfigUtils.getInstance().getOampConfig(OampConstants.JMX_SERVER_PORT);//9999
try {
// address =new JMXServiceURL("service:jmx:rmi:///jndi/rmi://127.0.0.1:9999/jmxrmi");
address =new JMXServiceURL("service:jmx:rmi:///jndi/rmi://"+jmxServerIp+":"+jmxServerPort+"/jmxrmi");
JMXConnector connector = JMXConnectorFactory.connect(address, null);
// address = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1234/jmxrmi");
// JMXConnector connector = JMXConnectorFactory.connect(address, props);
mbs= connector.getMBeanServerConnection();
connector.connect();
} catch (Exception e) {
SrvLogger.error("oamp", ClientMBServerManage.class, "Fail to getRemoteMBConn", e);
}
return mbs;
}



现在的方法:

/**
* 获取远程MBeanServerConnection
* @return
*/
private MBeanServerConnection getRemoteMBConn(){
// String user = "monitorRole";
// String pw = "password";
// String[] credentials = new String[] { user, pw };
// Map<String, String[]> props = new HashMap<String, String[]>();
// props.put("jmx.remote.credentials", credentials);
// JMXServiceURL address;
// MBeanServerConnection mbs=null;
// String jmxServerIp=ConfigUtils.getInstance().getOampConfig(OampConstants.JMX_SERVER_IP);//127.0.0.1
// String jmxServerPort=ConfigUtils.getInstance().getOampConfig(OampConstants.JMX_SERVER_PORT);//9999
// try {
// address =new JMXServiceURL("service:jmx:rmi:///jndi/rmi://"+jmxServerIp+":"+jmxServerPort+"/jmxrmi");
// JMXConnector connector = JMXConnectorFactory.connect(address, null);
// mbs= connector.getMBeanServerConnection();
// connector.connect();
// } catch (Exception e) {
// SrvLogger.error("oamp", ClientMBServerManage.class, "Fail to getRemoteMBConn", e);
// }

String jmxServerIp=ConfigUtils.getInstance().getOampConfig(OampConstants.JMX_SERVER_IP);//127.0.0.1
String jmxServerPort=ConfigUtils.getInstance().getOampConfig(OampConstants.JMX_SERVER_PORT);//9999
try{
MBeanServerConnection mbs=null;
JMXServiceURL address=new JMXServiceURL("service:jmx:rmi:///jndi/rmi://"+jmxServerIp+":"+jmxServerPort+"/jmxrmi");
Registry registry=LocateRegistry.getRegistry(jmxServerIp, Integer.parseInt(jmxServerPort));
RMIServer stub=null;
JMXConnector jmxc=null;
if (isVmConnector()) {
if (stub == null) {
stub = (RMIServer) registry.lookup("jmxrmi");
}
jmxc = new RMIConnector(stub, null);
jmxc.connect();
} else {
jmxc = JMXConnectorFactory.connect(address);
}
mbs=jmxc.getMBeanServerConnection();
return mbs;
} catch (Exception e) {
// e.printStackTrace();
SrvLogger.error("oamp", ServerMBClientManage.class, "Fail to getRemoteMBConn", e);
}
return null;
}
/**
* Returns true if this {@code ProxyClient} denotes
* a JMX connector for a JMX VM agent.
*/
private boolean isVmConnector() {
return true;
}



先记录下问题,JMX Remote时通过JMXConnectorFactory.connect(address, null);获取connector,在正常情况下一切ok,但是当两台机器时,一台作为服务器,一台作为客户机,当有一方把web服务重启时,然后再执行JMXConnectorFactory.connect(address, null);时,则会出现一些问题,不管怎么弄都出现问题,真的是没辙了。记得之前是解决了这个问题的,现在又出现了,并且没有丝毫的办法,哎。。。。。
出现的问题如下:

java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:338)
at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248)
at com.pachira.oamp.jmx.jmxServer.ServerMBClientManage.getRemoteMBConn(ServerMBClientManage.java:317)
at com.pachira.oamp.jmx.jmxServer.ServerMBClientManage.refreshClientConn(ServerMBClientManage.java:47)
at com.pachira.oamp.jmx.jmxServer.ServerMBClientManage.getRemoteMBeanRetry(ServerMBClientManage.java:75)
at com.pachira.oamp.jmx.jmxServer.ServerInitMBean.updateServerMBean(ServerInitMBean.java:79)
at com.pachira.oamp.jmx.MBean.Server.update(Server.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:93)
at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:27)
at com.sun.jmx.mbeanserver.MBeanIntrospector.invokeM(MBeanIntrospector.java:208)
at com.sun.jmx.mbeanserver.PerInterface.invoke(PerInterface.java:120)
at com.sun.jmx.mbeanserver.MBeanSupport.invoke(MBeanSupport.java:262)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1427)
at javax.management.remote.rmi.RMIConnectionImpl.access$200(RMIConnectionImpl.java:72)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1265)
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1360)
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:788)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.InitialContext.<init>(InitialContext.java:197)
at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1884)
at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1856)
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:257)
... 36 more
Caused by: java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:46)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
... 42 more
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值