Java includes a number of tools you can use to monitor your Java Virtual Machine (JVM). This tutorial covers some of the command line tools available to you in JDK 7.
Time to Complete
Approximately 45 minutes
Have you ever wanted to get information about a JVM that is already running? Find out things like what command line parameters were used to start the JVM or what was the
main method used to start the JVM?
Java SE 7 includes a number of tools you can use to monitor your Java Virtual Machine (JVM). In this tutorial, learn to use the
jps command and the new
jcmd command to get information about currently running JVMs on a system. Then, use the process information with
jstat to monitor JVM garbage collection activity locally and remotely.
Hardware and Software Requirements
The following is a list of hardware and software requirements:
- Windows XP or Windows 7 32 bit or 64 bit
- Java 7 Update 4 or later
- JEdit 4.5.1 or later
- NetBeans 7.1.2 later
- GlassFish 3.1.2 or later (Included with NetBeans)
- Java DB 10.8.1.2 or later (Included with NetBeans)
Note from the Author: At the time of this writing,
jcmd is not available on all platforms. The OBE was created using Windows 7 64 bit.
Before starting this tutorial, you should do the following:
- Install JDK 7 update 4
- Install JEdit
- Install NetBeans for Java EE 7.1.2 which includes Glassfish and Java DB.
- Make sure the JDK 7
bindirectory is included in the PATH for the system.
- Click Start > Computer to open the Windows that displays information about this computer.
- From the menu choose System Properties
- From the menu on the left choose Advanced System Settings
- From the Advanced tab, choose Environment Variables
- From system variables, choose the Path variable.
- Add the following to the path:
- Start JEdit
- Start NetBeans
- From the NetBeans Services tab start GlassFish. This will start GlassFish and JavaDB.
jps tool queries running JVMs on a system. By default, executing the command lists the JVMs running on your local system. The
jps command reports the local VM identifier (lvmid) for each instrumented JVM found. The lvmid is typically, but not necessarily, the operating system's process identifier for the JVM process.
With no options,
jps will list each Java application's lvmid followed by the short form of the application's class name or jar file name. The short form of the class name or JAR file name omits the class's package information or the JAR files path information. The
jps command uses the java launcher to find the class name and arguments passed to the main method.
The examples that follow are taken from a Windows 7 64 bit system running the following programs:
- JEdit - A Java programming editor
- NetBeans - A Java IDE
- GlassFish - A Java application server
- JavaDB - A database Server included with NetBeans
Note: The screenshots used in the examples were not all taken from the same session. Therefore, the process IDs may change from one screenshot to the next.
That covers most of the
jps options. You can use
jps to remotely connect to a system. The required configuration and steps are covered later in this OBE.
jcmd command is new in JDK 7 and provides many of the features of
jps plus some additional information as well. The
jcmd command allows you to query various aspects of specific virtual machines. Examples of some of these options are included below.
There are other command-line tools that can use the pid information generated from
jstat command-line tool displays detailed performance statistics for a local or remote HotSpot VM. The
–gctuil option is used most frequently to display garbage collection information.
Note: When using the Concurrent Mark Sweep (CMS) collector (also known as concurrent collector),
jstat reports two full GC events per CMS cycle, which is obviously misleading. However, young generation stats are accurate with the CMS collector.
jstat Utility Remotely
jstat command can also run remotely using the
jstatd utility. Note that
jstatd should not be run in a production environment and if security is a concern, running the command locally is preferred.
In this tutorial, you have learned how to:
- Query a system for running JVMs using
- Query a system for running JVMs using
- Query various performance aspects of a JVM using
- Perform command line performance monitoring locally and remotely using the
For additional information please visit the following links:
- jps Documentation
- jcmd Documentation
- jstat Documentation
- Java Performance Tuning and Optimization Course
- Curriculum Developer: Michael Williams
To help navigate this Oracle by Example, note the following:
- Hiding Header Buttons:
- Click the Title to hide the buttons in the header. To show the buttons again, simply click the Title again.
- Topic List Button:
- A list of all the topics. Click one of the topics to navigate to that section.
- Expand/Collapse All Topics:
- To show/hide all the detail for all the sections. By default, all topics are collapsed
- Show/Hide All Images:
- To show/hide all the screenshots. By default, all images are displayed.
- To print the content. The content currently displayed or hidden will be printed.
To navigate to a particular section in this tutorial, select the topic from the list.