简体   繁体   English

对象名称规范问题JMX

[英]Object name specification issue JMX

This is my code to read active sessions based on context 这是我的代码,用于根据上下文读取活动会话

try{

        String serviceUrl = "service:jmx:rmi:///jndi/rmi://localhost:9001/jmxrmi";

        JMXServiceURL jmxServiceUrl = new JMXServiceURL(serviceUrl);

        JMXConnector jmxc = JMXConnectorFactory.connect(jmxServiceUrl, null);

        MBeanServerConnection conn = jmxc.getMBeanServerConnection();

        ObjectName name = new ObjectName("Catalina:type=Manager,context=/generateBill,host=localhost,port=8080");
            System.out.println("sessionCounter generateBill");
        System.out.println(conn.getAttribute(name, "sessionCounter"));

        ObjectName name2 = new ObjectName("Catalina:type=Manager,context=/generateBillService,host=localhost,port=8080");
            System.out.println("sessionCounter generateBillService");
            System.out.println(conn.getAttribute(name2, "sessionCounter"));
        }
        catch (Exception e){
            e.printStackTrace();
        }

But I am getting javax.management.InstanceNotFoundException. 但是我正在获取javax.management.InstanceNotFoundException。 What is the solution for this problem? 这个问题有什么解决方案?

ObjectName name = new ObjectName( "Catalina:type=Manager,context=/examples,host=localhost"); ObjectName名称=新的ObjectName(“ Catalina:type = Manager,context = / examples,host = localhost”); System.out.println(conn.getAttribute(name, "activeSessions")); System.out.println(conn.getAttribute(name,“ activeSessions”));

No need to specify the port. 无需指定端口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM