本站首页    管理页面    写新日志    退出


«August 2025»
12
3456789
10111213141516
17181920212223
24252627282930
31


公告

戒除浮躁,读好书,交益友


我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:邢红瑞的blog
日志总数:523
评论数量:1142
留言数量:0
访问次数:9699744
建立时间: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();}%>  


阅读全文(4510) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.063 second(s), page refreshed 144757327 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号