How to get Java VM parameters

When working with Java application or any JVM based application, we might need to take a look at VM parameters that used to start the JVM process. We need to get different parameters and values for the following use cases also there could be more..

Use cases

  • Application crashes with OutOfMemory error.
  • Application suffers from garbage collection issues.
  • To analyze possible JVM performance tunings.
  • To analyze possible resource reductions.
  • Identifying conflicting VM parameters.

How to get Java VM Parameters of a running process

Command Line Tools

jps

jps -lv

l – application main class or jar
v – arguments passed to the JVM

jinfo

jinfo -flags [pid]

flags – prints arguments passed to the JVM in pairs.

jcmd

jcmd [pid] VM.flags

jcmd is the latest tool and can be used in place of jps and jinfo. All these tools doesn’t require JMX to be enabled. Also all these should be available with Java SDK without additional installations. You can get very rich set of data using jcmd also. To list down all the capabilities of jcmd you can use following command.

jcmd [pid/MainClass] help

jcmd is a separate topic itself, So I am not going to list all possible things with jcmd here. You can get a good idea about the features of it by executing different commands listed by above command.

GUI Tools

JConsole

You should have JMX setup in place for your application to use JConsole. Once its ready you can connect to the application by host and port.

JConsole remote connection

VisualVM

You can attach VisualVM to JVM process running on host machine or in a remote host. After attaching it will show JVM arguments in overview page. VisualVM is a handy tool when its comes to troubleshooting java applications.

VisuvalVM overview of JVM arguments
VisualVM overview on JVM arguments

Final Words

All listed tools are very useful for examining the running application VM arguments. But jcmd is the newer and it prints what we want in more readable manner. From GUI tools I prefer VisualVM. Try our Aptkode Dev Tools in your log4j2 tasks. Thanks for reading.

You may interested in following articles

Leave a Comment

Your email address will not be published. Required fields are marked *