前几天其他项目组同事跑过来和我说他们生产环境GC报警,基本情况是GC每秒执行90多次有时到200多次,经过两天多的排查,后来发现是代码某个方法发送消息完后就显示调用:
System.gc();
我看到这句代码立马就明白了!今天主要解决的问题还不是这个,而是在调试过程中遇到的jvisualvm(jdk1.6.0_45自带工具)连接到jboss(版本jboss-4.2.3.GA)报错的问题,报错信息如下:
15:05:48,062 ERROR [STDERR] javax.management.JMRuntimeException: Failed to load MBeanServerBuilder class org.jboss.mx.server.MBeanServerBuilderImpl: java.lang.ClassNotFoundException: org.jboss.mx.server.MBeanServerBuilderImpl
15:05:48,062 ERROR [STDERR] at javax.management.MBeanServerFactory.checkMBeanServerBuilder(MBeanServerFactory.java:480)
15:05:48,062 ERROR [STDERR] at javax.management.MBeanServerFactory.getNewMBeanServerBuilder(MBeanServerFactory.java:511)
15:05:48,062 ERROR [STDERR] at javax.management.MBeanServerFactory.newMBeanServer(MBeanServerFactory.java:298)
15:05:48,062 ERROR [STDERR] at javax.management.MBeanServerFactory.createMBeanServer(MBeanServerFactory.java:213)
15:05:48,062 ERROR [STDERR] at javax.management.MBeanServerFactory.createMBeanServer(MBeanServerFactory.java:174)
15:05:48,062 ERROR [STDERR] at sun.management.ManagementFactory.createPlatformMBeanServer(ManagementFactory.java:302)
15:05:48,062 ERROR [STDERR] at java.lang.management.ManagementFactory.getPlatformMBeanServer(ManagementFactory.java:504)
15:05:48,062 ERROR [STDERR] at sun.management.jmxremote.ConnectorBootstrap.startLocalConnectorServer(ConnectorBootstrap.java:458)
15:05:48,062 ERROR [STDERR] at sun.management.Agent.startAgent(Agent.java:135)
15:05:48,062 ERROR [STDERR] at sun.management.Agent.agentmain(Agent.java:95)
15:05:48,062 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
15:05:48,062 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
15:05:48,062 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
15:05:48,062 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:597)
15:05:48,062 ERROR [STDERR] at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:325)
15:05:48,062 ERROR [STDERR] at sun.instrument.InstrumentationImpl.loadClassAndCallAgentmain(InstrumentationImpl.java:348)
15:05:48,062 ERROR [STDERR] Caused by: java.lang.ClassNotFoundException: org.jboss.mx.server.MBeanServerBuilderImpl
15:05:48,062 ERROR [STDERR] at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
15:05:48,062 ERROR [STDERR] at java.security.AccessController.doPrivileged(Native Method)
15:05:48,062 ERROR [STDERR] at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
15:05:48,062 ERROR [STDERR] at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
15:05:48,062 ERROR [STDERR] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
15:05:48,062 ERROR [STDERR] at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
15:05:48,062 ERROR [STDERR] at javax.management.MBeanServerFactory.loadBuilderClass(MBeanServerFactory.java:423)
15:05:48,062 ERROR [STDERR] at javax.management.MBeanServerFactory.checkMBeanServerBuilder(MBeanServerFactory.java:465)
15:05:48,062 ERROR [STDERR] ... 15 more
15:05:48,078 ERROR [STDERR] 代理抛出异常 : javax.management.JMRuntimeException: Failed to load MBeanServerBuilder class org.jboss.mx.server.MBeanServerBuilderImpl: java.lang.ClassNotFoundException: org.jboss.mx.server.MBeanServerBuilderImpl
将错误信息在百度了很久后,试了各种还是连接报错。因为我自己还有其他事情处理,到了第二天,还是继续搜索解决方案,终于到一个国外帖子有人提到添加一个参数就可以了,抱着试试看的态度试了一下还真行,哎!这个连接到jboss就弄了我两天了。连接成功后面就定位到具体原因了(具体可以学习下怎么使用jvisualvm)。添加的参数为:
-Djboss.platform.mbeanserver=true
分两种情况,第一种:开发模式在Myeclipse里面配置jboss Server时,配置如下图:
第二种:单独启动jboss(点击jboss-4.2.3.GA\bin\run.bat启动),需要在run.bat里面添加该参数,如下图:
不管用哪种都行,启动jvisualvm连接到jboss的pid,效果图如下:
另外使用低版本的jdk是不带jvisualvm工具的或者有该工具但是没有抽样器选项卡的功能,再后来居然在ITeye有博客讲到,文章标题为“Jboss6的开启JMX配置用于远程监控”提到了该参数的添加,只是没有贴出遇到错误信息之类,也后悔我开始一直使用错误信息作为关键字找了那么久。今天我把错误信息包含到标题和正文内容里面,希望下个人快速定位到此出并解决该问题。