这是我的代码,用于根据上下文读取活动会话
尝试{
字符串serviceUrl =“ service:jmx:rmi:/// jndi / rmi:// localhost:9001 / jmxrmi”;
JMXServiceURL jmxServiceUrl =新的JMXServiceURL(serviceUrl);
JMXConnector jmxc = JMXConnectorFactory.connect(jmxServiceUrl,null);
MBeanServerConnection conn = jmxc.getMBeanServerConnection();
ObjectName名称=新的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”));
}
捕获(e例外){
e.printStackTrace();
}
但是我正在获取javax.management.InstanceNotFoundException。这个问题有什么解决方案?
最佳答案
ObjectName名称=新的ObjectName(“ Catalina:type = Manager,context = / examples,host = localhost”); System.out.println(conn.getAttribute(name,“ activeSessions”));
无需指定端口。
关于java - 对象名称规范问题JMX,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35315135/