jmx 서버를 이용하여 JCONSOLE을 쓸 수 있도록 할 수 있다..
public class JMXRmiServer { private final String jmxKey = "jmx.port"; private final int DEFAULT_PORT = 10000; private int port; private JMXFactory jmxFactory;
private ConnectorAgent agentBean; private String descriptor;
public JMXRmiServer(int port, String desc) { setPort(port); setDescriptor(desc); } private void setPort(int port) { if (port == 0) { port = DEFAULT_PORT; } this.port = port; } private void setDescriptor(String desc) { this.descriptor = desc; }
public void start() { this.jmxFactory = new JMXFactory(); if (descriptor != null) { jmxFactory.setDescriptorPath(descriptor); } jmxFactory.createManagedBaens(); try { MBeanServer mBeanServer = (MBeanServer)MBeanServerFactory.findMBeanServer(null).get(0); agentBean = new RMIConnectorAgent(); agentBean.init( port, mBeanServer); agentBean.start(); } catch( Exception e) { e.printStackTrace(); } }
public void end() { try { agentBean.stop(); } catch (Exception e) { e.printStackTrace(); } } } |