Getting Active Session counts with JMX (Java Management Extensions) API

java, jboss, jmx, web-applications

Solution

You can accomplish this by using something like JConsole or JVisualVM once you configure your app server to expose a JMX port. You don't mention which app server you're using but for Tomcat, it's described here: http://tomcat.apache.org/tomcat-5.5-doc/monitoring.html. Once you connect with JConsole, Tomcat exposes an MBean which has session information but again it depends which container you use.

Problem

I'm trying to use JMX API to get active session counts for a web application. - Is it possible to use JMX API to get this kind of information? - If yes, how reliable would it be? - Any example code on how to get this done? I've been reading JMX tutorial and documentation, but they are giving me the overview of what the technology is. I just can't pinpoint to what I need, yet.

Original source