这是我根据上下文读取活动会话的代码
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。这个问题的解决方案是什么?
答案 0 :(得分:1)
ObjectName name = new ObjectName(" Catalina:type = Manager,context = / examples,host = localhost"); System.out.println(conn.getAttribute(name," activeSessions"));
无需指定端口。