对象名称规范问题 JMX

Object name specification issue JMX

这是我根据上下文读取活动会话的代码

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();
        }

但我得到 javax.management.InstanceNotFoundException。这个问题的解决方案是什么?

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

无需指定端口。