tomcat7 - How can I write a java application using JMX code to get the active session's in tomcat 7? -


i using apache tomcat 7 run web application. need know number of active sessions running java application.

i have read possible using jmx. got count using jconsole. using java application need it.

can please me start it.

a simple approach be

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=protocolhandler,port=8080"); system.out.println(conn.getattribute(name, "connectioncount")); 

to find out more tomcat monitoring have @ monitoring , managing tomcat (or on local installation http://localhost:8080/docs/monitoring.html) , in faq - monitoring

edit find active sessions of application amend example accordingly. below 2 lines show acctive sessions if access sessionexample default tomcat installation.

objectname name = new objectname(     "catalina:type=manager,context=/examples,host=localhost"); system.out.println(conn.getattribute(name, "activesessions")); 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -