jstack and jcmd for JVM Debugging
jstack and jcmd for JVM analysis.
jstack
jstack and jcmd are JVM debugging tools. Engineers debugging Java applications use them to inspect running JVMs; the discipline accelerates incident response on JVM workloads.
What jstack provides:
- jstack PID dumps thread state.: The command outputs all the JVM threads with their current stacks. The team sees what each thread is doing; the analysis is grounded in real data.
- Find deadlocks.: Deadlocked threads are identified by jstack. The output shows the cycle; the team's investigation finds the deadlock; the fix is targeted.
- Find what threads are blocked on.: Each thread's blocked-on resource is shown. Locks, condition variables, IO; the discipline reveals the blocking source.
- Multiple snapshots.: Running jstack multiple times shows movement. Threads stuck in the same state across snapshots indicate persistent issues; transient blocks may not.
- Combined with profilers.: jstack is the entry point for JVM investigation. Once specific threads are identified, profilers (async-profiler, perf) provide deeper analysis.
jstack is the basic JVM debugging tool. Engineers' first reach for JVM thread issues.
jcmd
jcmd is the more comprehensive JVM tool. Heap dumps, GC inspection, thread dumps all are subcommands; the discipline scales beyond what jstack handles.
- jcmd PID GC.heap_dump path.hprof for heap dump.: The heap dump captures memory state. The team's analysis tools (Eclipse Memory Analyzer, similar) read the dump; memory leaks are identified.
- jcmd PID Thread.print equivalent to jstack.: jcmd can produce thread dumps too. The output is similar to jstack; the discipline can use either.
- jcmd PID GC.run forces garbage collection.: Useful during investigation to see post-GC memory state. The discipline accommodates specific testing.
- jcmd PID VM.flags shows JVM flags.: The active JVM flags are visible. Heap sizes, GC algorithms, debug flags all are revealed; the discipline supports configuration debugging.
- Many subcommands.: jcmd has many subcommands. The team learns the relevant ones; the discipline scales as needs evolve.
jcmd is the comprehensive tool. The discipline scales beyond simple thread dumps.
When
jstack and jcmd are reached for during JVM incidents. The discipline matches symptoms to tools.
- Java apps with high CPU or hung threads.: Symptoms suggesting JVM-level issues. High CPU; threads stuck; the team's investigation starts here.
- jstack first.: jstack is faster and lighter than heap dumps. The thread state often reveals the issue; the discipline starts simple.
- Heap dump if memory.: When memory is suspect, heap dump is the next step. The dump is large; the analysis takes time; the discipline reserves it for memory cases.
- Production safety.: jstack and jcmd have minimal production overhead. The team can use them during incidents without major impact.
- Combine with logs and metrics.: JVM tools are one input. Logs and metrics provide context; the team's investigation combines them; the analysis is comprehensive.
jstack and jcmd is one of those JVM debugging skills that pays off in Java incidents. Nova AI Ops integrates with application performance telemetry, complementing JVM-level investigation.