Java Monitoring Extension
JMX is one of the most useful way in java environment to debug applications.
We can use different JMX tools to connect to the JMX port and monitor the status of our application.
Information of the memory usage, the total number of instances, the object references etc can be tracked easily.
In tomcat we can use the startup scripts to set all kinds of parameters, or we can also enable JMX access by setting the CATALINA_OPTS environment variable.
On Unix machines we can create a file setenv.sh inside Tomcat’s bin directory with the following content:
This is read automatically during the startup.
On Windows machine, this can be set via setenv.bat.
We can add username and password to secure this port
export CATALINA_OPTS="-Dcom.sun.management.jmxremote.port=8090 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
After JMX port is setup we can connect to it using the jconsole tool or jvisualvm tool which is present in the jdk bin installation directory.
We can double click to lauch it or type “jconsole” or “jvisualvm” from the command prompt.
Once it is opened we can connect to it by typing the remote address and port number of the server.
If we have set the credentials at the server side then we need to provide them.
The JConsole interface in JDK is generally composed of the following six tabs:
Summary displays summary information on the JVM and monitored values.
Memory displays information about memory use.
Threads displays information about thread use.
Classes displays information about class loading.
MBeans displays information about MBeans.
VM displays information about the JVM.
Jvisualvm tool has many feature as compared to jconsole. We can analyze a heap dump and take memory snapshots, thread dump.
We can also use sampling option to take some sample of the desired classes in the memory.
Using jvisualvm we can also load heap dump of a any server and then analyze the heap dump offline.