Skip to main content
JVM tuning and diagnostics · Topic 4 of 5

Diagnostic tools (jcmd)

Definition​

jcmd talks to a running Java process by its process id. It can print thread stacks (to find deadlocks and stuck threads), show heap and class statistics, trigger a heap dump and start Flight Recorder, all without restarting the application.

Example code​

Looking inside a running JVM

jcmd # list running Java processes and their ids

jcmd <pid> Thread.print # all thread stacks; deadlocks are reported at the end
jcmd <pid> GC.heap_info # heap sizes and usage
jcmd <pid> GC.class_histogram # which classes use the most memory
jcmd <pid> GC.heap_dump /tmp/heap.hprof # a heap dump to open in a tool such as Eclipse MAT
jcmd <pid> JFR.start duration=60s filename=/tmp/rec.jfr # Flight Recorder: low-overhead profiling

Finished this page? Track your progress (saved only in your browser).