Overview
In the previous article, we navigate through jmap tool to analyze application performance, jmap is a console based which did not have a visual interface to analyze the data, In this article, we will understand one more profiling tool that is VisualVM.
Java VisualVM is a tool that provides a visual interface for viewing detailed information about Java applications while they are running on a Java Virtual Machine (JVM), and for troubleshooting and profiling these applications.
Various optional tools, including Java VisualVM, are provided with Sun’s distribution of the Java Development Kit (JDK) for retrieving different types of data about running JVM software instances. For example, most of the previously standalone tools
With help of VisualVM we can generate and analyze heap dumps, track down memory leaks, browse the platform’s MBeans and perform operations on those MBeans, perform and monitor garbage collection, and perform lightweight memory and CPU profiling.
VisualVM was introduced starting from Standard Edition of JDK 6. It is present as a tool till JDK 8. From Java 9 onward VisualVM is a separate project and no more part of JDK took-kit.
Starting Java VisualVM
Once we have installed an appropriate JDK version, navigate to your JDK software’s bin directory and double-click the Java VisualVM executable. On Windows this directory will be the following:
C:\Program Files\Java\jdk1.6.0_update-number\bin
Alternatively, navigate to your JDK software’s bin directory and type the following command at the command (shell) prompt:
jvisualvm
Java VisualVM Windows
When we start Java VisualVM, the main Java VisualVM window opens. The main Java VisualVM window is divided into two windows.

Applications Window
The Applications window opens in the left side of the main Java VisualVM window when we launch the application. The Applications window is the main point of entry for exploring the details of running applications. The Applications window uses a tree structure to enable us to quickly view the applications running on the local machine and any connected remote machines. We can also access core dumps (Solaris/Linux) and saved snapshots from the Applications window.
Main Window
Detailed information about applications is displayed in the main window. When you view data about an application, each application is represented by a tab in the main window that enables you to easily view and navigate the data. Saved thread dumps and heap dumps are also opened in the main window.
Profiling with Local Application
Let’s understand profiling with one of local application. Suppose we have attached program which is creating a 10000 objects.
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
package com.codenuclear; import java.util.ArrayList; import java.util.List; public class VisulVMTest { static List<VisulVMTest> visualVMTestList=new ArrayList<VisulVMTest>(); public static void main(String[] args) { for(int i=0;i<=10000;i++){ visualVMTestList.add(new VisulVMTest()); } while(true){ } } } |
1. The overview view:

The Overview tab displays the following general information about the application and the runtime environment.
- PID – Process ID of the application
- Host – The location of the system that the application is running on.
- Main class – The class containing the main method.
- Arguments – Displays any options passed to the application on startup.
- JVM – JDK version of the JVM software.
- Java Home -The location of the JDK software.
- Heap dump on OOME – This displays the status of the Heap Dump on OOME option. When enabled, a heap dump is taken when the application encounters an OutOfMemory exception. You can enabled or disable the option in the application popup menu.
2. The monitor view:

Monitoring data is displayed in the following graphs:
- Heap – The Heap graph displays the total heap size and how much of the heap is currently used. These are the figures that a Java technology-based application (Java application) can obtain using the java.lang.Runtime.totalMemory() and java.lang.Runtime.freeMemory() calls.
- PermGen – The PermGen graph displays changes in the permanent generation area over time. The permanent generation is the area of the heap where class and method objects are stored. If an application loads a very large number of classes, then the size of the permanent generation might need to be increased using the
-XX:MaxPermSize option. Classes The Classes graph displays an overview of the total number of loaded classes and shared classes. Threads. The Threads graphs display an overview of the number of live and daemon threads in the application’s JVM. You can use Java VisualVM to take a thread dump if you want to capture and view exact data on application threads at a specific point in time.
The Monitoring tab contains buttons that enable you to perform the following actions:
- Perform GC – Click Perform GC to perform garbage collection immediately.
- Heap Dump – Click Heap Dump to take a heap dump. When you take a heap dump, a tab displaying the heap dump opens in the application tab. A node for the heap dump appears under the node for the application in the Applications window.

3. The Threads View:

The information displayed in the Threads tab is based on Java Management Extensions (JMX). The Threads tab is visible if Java VisualVM can make a JMX technology-based connection (JMX connection) with the target application and retrieve JMX instrumentation from the Java Virtual Machine (JVM).
4. The Sampler View:

5. The Profiler View:

By default the profiling tool is not running until you are ready to profile the application. You can choose from the following profiling options:
CPU Profiling
This profile command returns detailed data on method-level CPU performance (execution time), showing the total execution time and number of invocations for each method. When analyzing application performance, Java VisualVM instruments all of the methods of the profiled application. Threads emit the “method entry” event when entering a method and generate the corresponding “method exit” event when exiting the method. Both of these events contain timestamps. This data is processed in real time.
Memory Profiling
Choose this to analyze the memory usage of the application. The results display the objects allocated by the application and the class allocating those objects.
Remote Application Profiling
Java VisualVM is able to access and display data about applications running on remote hosts. After connecting to a remote host, Java VisualVM can display general data about the application’s runtime environment and can monitor memory heap and thread activity.
To add a remote host, right-click the Remote node in the Applications window, choose Add Remote Host and type the host name or IP address in the Add Remote Host dialog box.

That’s all for VisualVM, Hope you like it, Keep reading and sharing !! :)
Hello there, You have done a great job. I will certainly digg it and for my part recommend to my friends. I am confident they will be benefited from this web site.|
Thanks to my father who stated to me concerning this web site, this blog is genuinely remarkable.|