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 閱讀(6298) 評論(1)  編輯  收藏 所屬分類: JAVATomcat

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

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


          網站導航:
           

          <2012年11月>
          28293031123
          45678910
          11121314151617
          18192021222324
          2526272829301
          2345678

          常用鏈接

          留言簿(2)

          隨筆分類(20)

          隨筆檔案(12)

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 会昌县| 宣化县| 治县。| 霸州市| 漠河县| 尖扎县| 洛南县| 靖安县| 辽宁省| 昭平县| 利辛县| 易门县| 阿拉尔市| 从化市| 化隆| 吴江市| 德安县| 修水县| 垦利县| 五华县| 延津县| 理塘县| 中方县| 金寨县| 宁国市| 二连浩特市| 乐业县| 炎陵县| 兴城市| 沧源| 喀喇| 石棉县| 任丘市| 麻栗坡县| 衡东县| 长春市| 北海市| 体育| 海林市| 福州市| 宾阳县|