JMX监控weblogic的JVM,报java.lang.ClassCastException错误

JMX监控weblogic的JVM,报java.lang.ClassCastException错误,请问这是什么原因,怎么解决?
环境:weblogic9.2 jdk1.5代码:
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Hashtable;
import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.naming.Context;

public class PrintJvmState {
   private static MBeanServerConnection connection;
   private static JMXConnector connector;
   private static final ObjectName service;
    // 实例化 RuntimeServiceMBean 对象名
   // 这样可以通过类使用此对象名。
   static {
      try {
         service = new ObjectName( "com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean");
      }catch (MalformedObjectNameException e) {
         throw new AssertionError(e.getMessage());
      }
   }
    /*
   * 实例化与 Domain Runtime MBean Server 的连接
   */
   public static void initConnection(String hostname, String portString, 
      String username, String password) throws IOException,
      MalformedURLException { 
      String protocol = "t3";
      Integer portInteger = Integer.valueOf(portString);
      int port = portInteger.intValue();
      String jndiroot = "/jndi/";
      String mserver = "weblogic.management.mbeanservers.runtime";
      JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname,
         port, jndiroot + mserver);
      Hashtable h = new Hashtable();
      h.put(Context.SECURITY_PRINCIPAL, username);
      h.put(Context.SECURITY_CREDENTIALS, password);
      h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,
         "weblogic.management.remote");
      connector = JMXConnectorFactory.connect(serviceURL, h);
      connection = connector.getMBeanServerConnection();
   }




   public static ObjectName[] getJVMRuntime() throws Exception {
                   ObjectName serviceRT = (ObjectName) connection.getAttribute(service, "ServerRuntime");
      return (ObjectName[]) connection.getAttribute(serviceRT, "JVMRuntime");
   }
    /* 
   * 迭代 ServerRuntimeMBean,获取名称和状态
   */
   public void printJvmInformation() throws Exception {
                   ObjectName[] jvmRT = getJVMRuntime();
      System.out.println("got jvm runtimes");
      int length = (int) jvmRT.length;
      for (int i = 0; i < length; i++) {
               String name = (String) connection.getAttribute(jvmRT, "Name");
         int HeapSizeCurrent = Integer.parseInt(String.valueOf(connection.getAttribute(jvmRT, "HeapSizeCurrent")));
         int HeapFreeCurrent = Integer.parseInt(String.valueOf(connection.getAttribute(jvmRT, "HeapFreeCurrent")));
         int HeapFreePercent = Integer.parseInt(String.valueOf(connection.getAttribute(jvmRT, "HeapFreePercent")));
         System.out.println("Server name: " + name + ".HeapSizeCurrent: " + HeapSizeCurrent + "HeapFreeCurrent: " + HeapFreeCurrent + "HeapFreePercent: " + HeapFreePercent);
                   }
   }
    public static void main(String[] args) throws Exception {
      String hostname = "*。*。*。*";
      String portString = "7001";
      String username = "weblogic";
      String password = "weblogic";
      PrintJvmState jvm = new PrintJvmState();
      initConnection(hostname, portString, username, password);
      jvm.printJvmInformation();
      connector.close();
   }
}



[i][i][i]报错信息:
Exception in thread "main" java.lang.ClassCastException: javax.management.Object
Name
        at PrintJvmState.getJVMRuntime(PrintJvmState.java:50)
        at PrintJvmState.printJvmInformation(PrintJvmState.java:56)
        at PrintJvmState.main(PrintJvmState.java:74)
[/i][/i][/i]
参与5

4同行回答

Ajax0816Ajax0816系统运维工程师picc
回复 4# zhuqinghu 我按照第一个链接加了那个参数,还是报一样的错java  -Dsun.lang.ClassLoader.allowArraySyntax=true  PrintJvmState我确实安装了1.6的jre,但是我配置了环境变量,现在在dos里执行java -version,显示的是1.5的版本java version "1.5.0_...显示全部
回复 4# zhuqinghu


我按照第一个链接加了那个参数,还是报一样的错
java  -Dsun.lang.ClassLoader.allowArraySyntax=true  PrintJvmState
我确实安装了1.6的jre,但是我配置了环境变量,现在在dos里执行java -version,显示的是1.5的版本
java version "1.5.0_17"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_17-b04)
Java HotSpot(TM) Client VM (build 1.5.0_17-b04, mixed mode, sharing)收起
互联网服务 · 2013-08-06
浏览1193
zhuqinghuzhuqinghu系统工程师XX科技
你在initConnection方法的JMXConnectorFactory.connect方法处以加上抛出异常并打印出错信息及getJVMRuntime处打印出错信息,应当就可以看到详细的信息问题处理可参考  http://www.docin.com/p-665252607.html以及http://blog.chinaunix.net/uid-23602383-id-3202607.htm...显示全部
你在initConnection方法的JMXConnectorFactory.connect方法处以加上抛出异常并打印出错信息及getJVMRuntime处打印出错信息,应当就可以看到详细的信息
问题处理可参考  
http://www.docin.com/p-665252607.html以及
http://blog.chinaunix.net/uid-23602383-id-3202607.html
第一个链接的可能性要大些收起
互联网服务 · 2013-08-06
浏览1195
Ajax0816Ajax0816系统运维工程师picc
回复 2# 徐霞客 不好意思啊,重新编辑了,麻烦帮忙看看,谢谢显示全部
回复 2# 徐霞客


不好意思啊,重新编辑了,麻烦帮忙看看,谢谢收起
互联网服务 · 2013-08-06
浏览1140
徐霞客徐霞客产品经理保密
楼主编辑下你的帖子,都看不清楚怎么回答?代码可以通过插入代码来添加显示全部
楼主编辑下你的帖子,都看不清楚怎么回答?代码可以通过插入代码来添加收起
互联网服务 · 2013-08-06
浏览1142

提问者

Ajax0816
系统运维工程师picc

相关问题

问题状态

  • 发布时间:2013-08-06
  • 关注会员:1 人
  • 问题浏览:4779
  • 最近回答:2013-08-06
  • X社区推广