2012-07-10 70 views

回答

2

那麼,我寫了我自己的JMXMP Tomcat監聽器。隨意使用:

package webersg.tomcat; 

import java.lang.management.ManagementFactory; 

import javax.management.remote.JMXConnectorServer; 
import javax.management.remote.JMXConnectorServerFactory; 
import javax.management.remote.JMXServiceURL; 

import org.apache.catalina.Lifecycle; 
import org.apache.catalina.LifecycleEvent; 
import org.apache.catalina.LifecycleListener; 

public class JMXMPLifecycleListener implements LifecycleListener { 

    private int port = 5555; 

    private JMXConnectorServer cs; 

    @Override 
    public void lifecycleEvent(LifecycleEvent event) { 

     try { 

      // START 
      if (Lifecycle.START_EVENT == event.getType()) { 

       System.out.println("Start JMXMP on port " + port); 

       cs = JMXConnectorServerFactory.newJMXConnectorServer(
         new JMXServiceURL("jmxmp", "0.0.0.0", port), 
         null, 
         ManagementFactory.getPlatformMBeanServer() 
       ); 
       cs.start(); 

       System.out.println("Started JMXMP"); 

      } 

      // STOP 
      else if (Lifecycle.STOP_EVENT == event.getType()) { 

       System.out.println("Stop JMXMP"); 

       cs.stop(); 
      } 

     } catch (Exception e) { 
      throw new RuntimeException(e); 
     } 
    } 

} 

因此,經過一天在這個問題上突破我的頭,我現在能夠在我的應用程序上使用VisualVM。

3

我創建了一個基於Bart von Heukeloms' answer與所需的tomcat-卡塔利娜爲提供相關性的MVN項目:jmxmp-lifecycle-listener

只是在被插入到Tomcat的server.xml:
<Listener className="javax.management.remote.extension.JMXMPLifecycleListener" port="5555" />

我沒有足夠的聲望,否則我會張貼這個評論。