Tomcat uses JMX to see how the Web-app is running __web

Source: Internet
Author: User
Tomcat uses JMX to view the operation of the Web-app

JMX is already a standard component of J2SE in JDK 1.5.
In 1.4, JMX is defined by Sun specification and implemented by other companies.
Tomcat uses the JMX implemented by Sun Company.
Each version of Tomcat is different,
In Tomcat5, you can find a jmx.jar,4.1.x version in the bin directory, Server/lib/mx4j-jmx.jar
Here is an example
<% @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 ();
}
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.