| 
 
| 
| 
| | « | October 2025 | » |  | 日 | 一 | 二 | 三 | 四 | 五 | 六 |  |  |  |  | 1 | 2 | 3 | 4 |  5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |  | |  | 
 |  公告
 |  
| 戒除浮躁,读好书,交益友 |  
 
 
 
 
 
 
| Blog信息 |  
| blog名称:邢红瑞的blog日志总数:523
 评论数量:1142
 留言数量:0
 访问次数:9729525
 建立时间:2004年12月20日
 |   
 
 |  | 
 
|  [j2ee]tomcat使用jmx查看web-app的运行情况 原创空间,  软件技术
 邢红瑞 发表于 2005/10/11 13:42:06  |  
| 
| JMX 在JDK 1.5中已经是J2SE的一个标准组成部分了。在1.4中,JMX由SUN定义规范,其他公司进行实现。Tomcat中使用的是SUN公司实现的JMX。tomcat的各个版本情况不同,在Tomcat5中,可以在bin目录下找点jmx.jar,4.1.X版本,server\lib\mx4j-jmx.jar以下是个例子<%@page contentType="text/plain;charset=GBK"%><%@page import="java.util.Iterator"%><%@page import="java.util.Set"%><%@page import="javax.management.MBeanServerFactory"%><%@page import="javax.management.MBeanServer"%><%@page import="javax.management.ObjectName"%><%@page import="javax.management.MBeanInfo"%><%@page import="javax.management.MBeanAttributeInfo"%><%out.clear(); MBeanServer mBeanServer = null;if(MBeanServerFactory.findMBeanServer(null).size() > 0){  mBeanServer = (MBeanServer)MBeanServerFactory.findMBeanServer(null).get(0);}else{  mBeanServer = MBeanServerFactory.createMBeanServer();} Set names = null;try {  names=mBeanServer.queryNames(new ObjectName("*:j2eeType=WebModule,*"), null);  out.println("OK - Number of results: " + names.size());  out.println();} catch (Exception e) {  out.println("Error - " + e.toString());  return;} Iterator it=names.iterator();while( it.hasNext()) {  ObjectName oname=(ObjectName)it.next();  out.println( "Name: " + oname.toString());    try {    MBeanInfo minfo=mBeanServer.getMBeanInfo(oname);    // can't be null - I thinl    String code=minfo.getClassName();    if ("org.apache.commons.modeler.BaseModelMBean".equals(code)) {      code=(String)mBeanServer.getAttribute(oname, "modelerType");    }    out.println("modelerType: " + code);        MBeanAttributeInfo attrs[]=minfo.getAttributes();    Object value=null;        for( int i=0; i< attrs.length; i++ ) {      if( ! attrs[i].isReadable() ) continue;      //if( ! isSupported( attrs[i].getType() )) continue;      String attName=attrs[i].getName();      if( attName.indexOf( "=") >=0 ||        attName.indexOf( ":") >=0 ||        attName.indexOf( " ") >=0 )      {        continue;      }            try {        value=mBeanServer.getAttribute(oname, attName);      } catch( Throwable t) {        System.out.println("Error getting attribute " + oname +        " " + attName + " " + t.toString());        continue;      }      if( value==null ) continue;      if( "modelerType".equals( attName)) continue;      String valueString=value.toString();      //out.println( attName + ": " + escape(valueString));      out.println( attName + ": " + valueString);    }  } catch (Exception e) {      }  out.println();}%> |  
 |  
 
 
 
 |