0
votes

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?

1
Please post the full error.Boris the Spider
P.S. why is there a space in the webapp's context?Boris the Spider
no there is no spaceSreevidya Aravind
context=/ testapp2 - there is in the code you posted.Boris the Spider
I gave a dummy name. In actual condition there is no space .Sreevidya Aravind

1 Answers

1
votes

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

No need to specify the port.