This is the third article in the series of articles exploring the tools and techniques for analyzing, monitoring, and improving the performance of Java applications.
The Art of Java Application Performance Analysis and Tuning-Part 4 The Art of Java Application Performance Analysis and Tuning-Part 5 The Art of Java Application Performance Analysis and Tuning-Part 6 The Art of Java Application Performance Analysis and Tuning-Part 7
In this blog we will continue to look at some of the useful tools for analyzing the Java application programs.
The JConsole graphical user interface is a monitoring tool and used to monitor memory consumption, CPU consumption, threads and class information, etc.. of applications running on the Java platform. JConsole graph views can be used to monitor the resource
usage of the Java application over time.
Connecting JConsole to a Java Application
On Linux/Unix machines:
/usr/local/jdk1.6.0_17/bin/jconsole //To connect Local Application. Need to select Java Process in the GUI /usr/local/jdk1.6.0_17/bin/jconsole <PID> //Local Application, with PID /usr/local/jdk1.6.0_17/bin/jconsole 10.209.96.221:9999 // Remote Application
On Windows machines:
Double click the jconsole.exe program in c:\Program Files\Java\bin\jconsole.exe
Upon opening JConsole client window (Fig B.), connect the local java process by identifying the java process in Local Processes list. (or) connect the remote java process by giving the host name and port number.
JConsole Remote Server configuration : add below lines to server java command for remote monitoring
-Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=9999
Once you have connected JConsole to an application, JConsole is composed of six tabs.
- Overview: Displays overview information about the Java VM and monitored values.
- Memory: Displays information about memory use.
- Threads: Displays information about thread use.
- Classes: Displays information about class loading.
- VM: Displays information about the Java VM.
- MBeans: Displays information about MBeans.
The Overview tab (Fib C.) displays graphical monitoring information about CPU usage, memory usage, thread counts, and the classes loaded in the Java VM, all in a single screen. This can be used to monitor the application for period of time
The Memory tab (Fig D.) provides information about memory consumption and memory pools. If the memory curve touches the maximum memory alloted, then we can suspect OutOfMemory (or) high memory usage.
A well behaved application will have a rhythmic graph curve (Fig D.) over the time.
We can use “Perform GC” option to manually start the Garbage Collection. This can be used confirm OutOfMemory Error/high memory usage. Even after the “Perform GC” if the memory is not coming down, then we can suspect OutOfMemory Error/high memory usage.
Monitoring Thread use
The Threads tab (Fig E.) provides information about thread use. It gives the number of threads running in the application. We can get the “stack trace” of a particular thread by clicking the thread name on left side panel.
If the number of threads increasing continuously then we can suspect the thread leak.
Detecting Deadlocked Threads
To check if your application has run into a deadlock (for example, your application seems to be hanging), deadlocked threads can be detected by clicking on the “Detect Deadlock” button. If any deadlocked threads are detected, these are displayed in a new tab that appears next to the “Threads” tab.
Monitoring Class Loading
The Classes tab (Fig F.) displays information about class loading. This gives the number of classes loaded in the system.
In some rare cases we can get class leaks and can lead to OutOfMemory Error.
The VM Summary tab provides information about the Java VM.
The MBeans tab displays information about all the MBeans registered with the platform MBean server in a generic way. If you are using libraries like Hibernate..then you can get statistics using MBean tab.
“JConsole” can be used to connect IBM Java VM
More Details at: