archive for may, 2007

  
  

jvmstat

on 2007-05-06 at 15:17 in java

ever had multiple Java background processes running on your system and wondered what is the best way to find out which process is executing a particular Java program? ever had one out of a number of JVMs consuming all memory and/or CPU and you simply want to know which program to blame for?

usually you can track down the Java program being executed by a particular JVM with a detailed look at the output of the ps command on a POSIX compliant OS or by investigating processes with Sysinternals (recently acquired by Microsoft) Process Explorer on a Microsoft Windows OS.

yesterday i found out that there is a much easier way to get a list of all JVM processes and the Java program (main class) being executed by each JVM, namely jps. jps is part of jvmstat which is included with J2SE since version 5.0 and available as a separate download for earlier versions. jps lists all JVM processes currently running together with the main class being executed:

# jps -l
10152 sun.tools.jps.Jps
32606 org.jboss.Main
#
			

depending on the command line options used further details of each JVM process (such as the arguments passed to the JVM and the main method) can be revealed. surprisingly jps can be written in a few lines of Java using an undocumented API that appeared in J2SE 5.0. the other tools jstat and visualgc, also part of jvmstat, might be especially useful to debug performance problems.

at the moment it looks like the jvmstat features are only implemented by the Sun JVM. it would be interesting to see if other JVM implementations provide similar features and command line tools.