To profile any Java application there are many options, ranging from free to very expensive.
However, one of the best free options is included in the Java Virtual Machine (JVM): VisualVM. This is
the tool you can use to profile batch jobs. Before you begin profiling your jobs, let's take a quick tour of
the VisualVM tool.
A Tour of VisualVM
Oracle's VisualVM is a tool that gives you insights into what is going on in your JVM. As JConsole's big
brother, VisualVM provides not only JMX administration like JConsole but also information about CPU
and memory usage, method execution times, as well as thread management and garbage collection. This
section looks at the capabilities of the VisualVM tool.
Before you can try VisualVM, you have to install it. If you're running an Oracle distribution of the
JDK version greater than version 6 update 7, then you've already installed it because it comes with the
JDK. If you're running a different version of Java, you can obtain VisualVM from Oracle directly at
With VisualVM installed, you can launch it. VisualVM greets you with a menu on the left and a Start
Page on the right, as shown in Figure 11-1.
Figure 11-1. The start screen for VisualVM
The menu on the left is broken into four sections: Local and Remote are where you find applications
that you can connect to, to profile. When you start VisualVM, because it's itself a Java application, it
appears in the Local section. Below the Local and Remote sections are where you can load either Java
VM coredumps that you've collected previously that you want to analyze; or snapshots, which are the
state of a VM at a certain point in time that you can capture using VisualVM. To see some of the
capabilities of the VisualVM tool, let's connect VisualVM to an instance of Eclipse.
When you first connect to a running JVM, VisualVM displays the screen shown in Figure 11-2.