How to set JMX remote port system environment parameters through java code for remote monitoring?

后端 未结 6 1226
长发绾君心
长发绾君心 2020-12-29 13:33

I have a program which requires dynamically (i.e. at run time) opening an available socket and start a JMX agent on it. This JMX parameters are being set inside the Java cod

6条回答
  •  既然无缘
    2020-12-29 14:00

    You're going about this slightly the wrong way. By the time your code is called you've missed the chance for these properties to have any effect.

    You need to create an RmiRegistry and then create a JMXConnectorServer linked to the platform MBeanServer like this:

    private void createJmxConnectorServer() throws IOException {
        LocateRegistry.createRegistry(1234);
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://localhost/jndi/rmi://localhost:1234/jmxrmi");
        JMXConnectorServer svr = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
        svr.start();
    }
    

提交回复
热议问题