I've downloaded the JMXMP extensions并将它们安装在Tomcat的lib目录中。现在,我该如何使用它们,即让Tomcat接受JMXMP连接?
最佳答案
好吧,我编写了自己的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。