Video in progress

Which JDK tools do you know for observing a running Java application?

The main ones: jps (list of processes), jcmd (universal diagnostics), jstat (GC statistics), jstack (thread dump), jmap (heap), and graphical tools: JConsole, VisualVM, JDK Mission Control.

📖 Answer

I usually use them in this order:

jps -l                        # which java processes exist, the PID
jcmd 12345 help               # which commands this JVM supports
jstat -gcutil 12345 1000      # GC state every second, in %
jcmd 12345 Thread.print       # thread dump
jcmd 12345 GC.class_histogram | head -20   # the classes taking the most space

jcmd is the main tool now. It does most of what jstack, jmap and jinfo do, under a single command.

On the graphical side: JConsole comes with the JDK and shows heap, thread and class count graphs over JMX. VisualVM is a separate download, with a sampling profiler and a heap dump viewer. JDK Mission Control is mainly for analyzing JFR recordings.

One catch: to attach to the process, these tools need you to be the same OS user. In a container you usually kubectl exec and run jcmd 1 ... inside: the Java process is often PID 1.