posts - 19,  comments - 11,  trackbacks - 0
          Tomcat 5.5.20可以使用JMX服務進行管理操作。下面介紹如何查看Tomcat提供哪些JMX服務,并如何使用這些JMX服務。


          1. 使用JDK1.5自帶的JConsole程序查看Tomcat的JMX服務

            要讓JConsole能查看到Tomcat的JMX服務,需要Tomcat啟動一個管理口。由于tomcat5.5.20缺省啟動文件不提供JMX服務接口 加入下面紅色內容到catalina.bat:

          set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote.port=1090 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file="%CATALINA_BASE%\conf\logging.properties" 
          啟動Tomcat5.5.20

          再運行jdk1.5的jconsole程序

          d:\jdk1.5\bin\jconsole nnnnn          (nnnn 是tomcat的進程號 用Task Manager查


          2. 調用Tomcat的JMX服務,如停止、啟動web應用
          寫一個JavaBean,用來調用Tomcat的JMX服務,關鍵方法如下:
          public static boolean callWebModuleMBeanMethod(String appName,String methodName) throws Exception
          MBeanServer mBeanServer 
          = null
            
          if (MBeanServerFactory.findMBeanServer(null).size() > 0
          mBeanServer 
          = (MBeanServer) MBeanServerFactory.findMBeanServer( 
          null).get(0); 
          }
           else 
          throw new Exception("cann't find catalina MBeanServer"); 
          }
           
            
          Set names 
          = null
          try 
          names 
          = mBeanServer.queryNames(new ObjectName( 
          "*:j2eeType=WebModule,name=//localhost/"+appName+",*"), null); 
          }
           catch (Exception e) 
          throw new Exception("cann't find "+appName+ " web moudule mbean! can't undeploy web app.\n"+e.getMessage()); 
          }
           
          if(names==null || names.size()==0
          log.debug(
          "can't find "+appName+ " web moudule mbean!"); 
          return false
          }
           
            
          ObjectName oname 
          =null
          Iterator it 
          = names.iterator(); 
          if (it.hasNext()) 
          oname
          =(ObjectName) it.next(); 
          }
           
            
          if(oname==null
          return false
          try 
          mBeanServer.invoke(oname,methodName,
          null,null); 
          return true
          }
           catch (Exception e) 
          throw new Exception("can't "+methodName+" "+appName+ " web application!\n"+e.getMessage()); 
          }
           
          }
           
            
          public static void main(String[] args)
          callWebModuleMBeanMethod(
          "app1","stop"); //停止web應用app1 
          callWebModuleMBeanMethod("app1","start"); //啟動web應用app1 
          }
           
          posted on 2009-04-21 13:30 happyy2k 閱讀(6292) 評論(1)  編輯  收藏 所屬分類: JAVATomcat

          FeedBack:
          # re: 使用Tomcat的jmx服務
          2012-11-25 18:48 | cydyhty
          你確定能用?  回復  更多評論
            

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          <2009年4月>
          2930311234
          567891011
          12131415161718
          19202122232425
          262728293012
          3456789

          常用鏈接

          留言簿(2)

          隨筆分類(20)

          隨筆檔案(12)

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 芜湖市| 通辽市| 东乡族自治县| 房产| 洪泽县| 屯门区| 松桃| 汕头市| 和平区| 英吉沙县| 图木舒克市| 友谊县| 汽车| 天镇县| 彭州市| 集安市| 德格县| 荔浦县| 贵定县| 黄大仙区| 历史| 新竹市| 台安县| 灵山县| 韶关市| 天镇县| 阿拉尔市| 萨嘎县| 林芝县| 綦江县| 玉屏| 双桥区| 大安市| 温宿县| 乡城县| 屯门区| 温泉县| 上思县| 台山市| 铜梁县| 雷山县|