JMX连接挂起

时间:2018-08-20 18:45:16

标签: java jmx jdmk opendmk

使用以下超级简单的Java应用程序:

class Main {
    static final private Logger logger = LoggerFactory.getLogger(Main.class);

    public static void main(String[] args) throws Exception {
        JMXServiceURL url = new JMXServiceURL(null, "localhost", 9999);
        logger.info("got JMXServiceURL");
        logger.info(String.format("JMXServiceURL=%s", url.toString()));

        try (JMXConnector connector = JMXConnectorFactory.connect(url)) {
            logger.info("got JMXConnector");
            MBeanServerConnection connection = connector.getMBeanServerConnection();
            logger.info("got MBeanServerConnection");
            logger.info(String.format("connection.getMBeanCount()=%d", connection.getMBeanCount()));
        }

        logger.info("exiting");
    }
}

我正在使用具有依赖性的最小build.gradle文件:

dependencies {
  implementation 'ch.qos.logback:logback-classic:1.2.3'
  implementation 'org.jvnet.opendmk:jmxremote_optional:1.0_01-ea'
}

没有jmxremote_optional依赖项,我收到了java.net.MalformedURLException: Unsupported protocol: jmxmp错误。我想我已经添加了正确的Maven依赖关系来解决该问题。

运行此命令时,得到以下信息,然后应用程序无限期挂起:

120     18:43:33.693 [main] INFO  jmxclient.Main - got JMXServiceURL
123     18:43:33.696 [main] INFO  jmxclient.Main - JMXServiceURL=service:jmx:jmxmp://localhost:9999

我肯定有一个Java应用程序在该端口上公开JMX指标:

time curl localhost:9999
curl: (52) Empty reply from server

real    0m0.020s
user    0m0.012s
sys 0m0.000s

0 个答案:

没有答案