Operations 6 min read

Mastering jcmd: Essential Java Debugging Commands and Examples

jcmd, introduced in JDK 7, is a powerful built‑in Java diagnostic tool that lets you send commands to running JVMs, replace utilities like jstack and jmap, and perform tasks such as listing processes, printing thread stacks, retrieving heap information, and using Java Flight Recorder.

Programmer DD
Programmer DD
Programmer DD
Mastering jcmd: Essential Java Debugging Commands and Examples

jcmd Overview

jcmd is a built‑in JDK tool introduced in JDK 7, offering powerful diagnostic capabilities that can replace tools such as jstack and jmap.

It sends diagnostic commands to a JVM; for security, the user must match the Java process’s user and group.

Syntax

jcmd [pid|main-class] command... | PerfCounter.print | -f filename
jcmd -l
jcmd -h

pid or main‑class identifies the target JVM; command specifies the operation.

-f filename – read commands from a file

-l – list JVMs not running in Docker

-h – help

Common Commands

List running JVMs jcmd -l Outputs all active JVM processes, similar to jps.

Print thread stack jcmd <pid> Thread.print -l The -l flag includes lock information from java.util.concurrent.

Example output shows thread details and locked synchronizers.

Heap information jcmd <pid> GC.heap_info Retrieves heap statistics.

Heap dump jcmd <pid> GC.heap_dump heap_dump.out Creates a heap dump file named heap_dump.out.

Class histogram jcmd <pid> GC.class_histogram Shows the number of instances and memory usage per class, useful for performance analysis.

Java Flight Recorder (JFR)

jcmd also supports JFR commands such as JFR.start, JFR.dump, JFR.stop, providing event recording capabilities inside the JVM.

Explore additional jcmd functions to enhance Java diagnostics.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DebuggingHeap DumpjcmdJFRJVM diagnostics
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.