服务器

位置:IT落伍者 >> 服务器 >> 浏览文章

使用Tomcat的jmx服务


发布日期:2019年05月21日
 
使用Tomcat的jmx服务

Tomcat 可以使用JMX服务进行管理操作下面介绍如何查看Tomcat提供哪些JMX服务并如何使用这些JMX服务

. 使用JDK自带的JConsole程序查看Tomcat的JMX服务

要让JConsole能查看到Tomcat的JMX服务需要Tomcat启动一个管理口由于tomcat缺省启动文件不提供JMX服务接口 加入下面红色内容到catalinabat

set JAVA_OPTS=%JAVA_OPTS% Dcomsunmanagementjmxremoteport= Dcomsunmanagementjmxremotessl=false Dcomsunmanagementjmxremoteauthenticate=false Djavautilloggingmanager=orgapachejuliClassLoaderLogManager Djavautilloggingconfigfile=%CATALINA_BASE%confloggingproperties

启动Tomcat

再运行jdk的jconsole程序

d:jdkbinjconsole nnnnn(nnnn 是tomcat的进程号 用Task Manager查)

. 调用Tomcat的JMX服务如停止启动web应用

写一个JavaBean用来调用Tomcat的JMX服务关键方法如下

public static boolean callWebModuleMBeanMethod(String appNameString methodName) throws Exception{

MBeanServer mBeanServer = null;

if (MBeanServerFactoryfindMBeanServer(null)size() > ) {

mBeanServer = (MBeanServer) MBeanServerFactoryfindMBeanServer(

null)get();

} else {

throw new Exception(cannt find catalina MBeanServer);

}

Set names = null;

try {

names = mBeanServerqueryNames(new ObjectName(

*:jeeType=WebModulename=//localhost/+appName+*) null);

} catch (Exception e) {

throw new Exception(cannt find +appName+ web moudule mbean! cant undeploy web appn+egetMessage());

}

if(names==null || namessize()==) {

logdebug(cant find +appName+ web moudule mbean!);

return false;

}

ObjectName oname =null;

Iterator it = namesiterator();

if (ithasNext()) {

oname=(ObjectName) itnext();

}

if(oname==null)

return false;

try {

mBeanServerinvoke(onamemethodNamenullnull);

return true;

} catch (Exception e) {

throw new Exception(cant +methodName+ +appName+ web application!n+egetMessage());

}

}

public static void main(String[] args){

callWebModuleMBeanMethod(appstop); //停止web应用app

callWebModuleMBeanMethod(appstart); //启动web应用app

}

               

上一篇:Spring框架将推出企业级Web服务器

下一篇:JBoss Web和Tomcat的区别[2]