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. What is the solution for this problem?
context=/ testapp2- there is in the code you posted. - Boris the Spider