MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

jstack Utility Deep Dive: JVM Thread Dumps, Deadlocks, and Mixed Stacks

Originally published on 2016-01-25; fully revised and updated.

The jstack utility is a JVM troubleshooting tool for capturing thread dumps and detecting deadlocks. This article is for DevOps and platform engineers who need fast, reliable thread-level diagnostics in production or pre-production environments, with practical commands and a clear triage workflow.

jstack utility overview

Where jstack fits in JVM diagnostics

Oracle JDK 8 troubleshooting documentation introduced Java Mission Control, Java Flight Recorder, and jcmd, and suggests using jcmd instead of jstack for enhanced diagnostics and lower overhead in many cases. Even so, jstack remains a direct and widely used way to obtain thread dumps, detect deadlocks, inspect core files, and print mixed Java/native stacks.

ToolPosition in JDK 8 docsBest useNotes
jstackLegacy but fully documented troubleshooting utilityThread dumps, deadlock detection, mixed stacks, core-dump analysisSimple and direct for stack-centric debugging
jcmdSuggested in JDK 8 docs as the newer diagnostic utilityBroader diagnostics with command-based interfacePreferred by JDK 8-era guidance for reduced overhead

What jstack can collect

  • Stack traces for all threads attached to a JVM, including Java threads and VM internal threads.
  • Deadlock detection in Java-level locking scenarios.
  • Ownable synchronizer details with -l (including java.util.concurrent.locks information).
  • Mixed Java and native C/C++ frames with -m.
  • Stack traces from a core dump.
  • Remote querying via jsadebugd (with slower output, as noted in the source material).

Thread-dump methods and when to use them

MethodCommand or actionUse caseImportant notes
Standard dumpjstack <pid>General hang/latency investigationEquivalent output to Ctrl+\ or QUIT signal per Oracle docs
Dump with synchronizersjstack -l <pid>Lock contention and concurrency debuggingAdds ownable synchronizer details
Forced dumpjstack -F <pid>When the normal command does not respondSource notes Solaris/Linux support
Mixed stackjstack -m <pid>JNI/native or VM-level investigationIncludes C/C++ frames as well as Java frames
Core-file analysisjstack $JAVA_HOME/bin/java corePost-crash/offline analysisRequires JVM binary and core file
Programmatic captureThread.getAllStackTraces()Application-level diagnosticsUseful when adding in-app debug capability
Debugger viewwhere in jdbInteractive debugging sessionsConvenient in live debug workflows

Practical jstack command examples

Standard thread dump

jstack <pid>Code language: HTML, XML (xml)

Include ownable synchronizers

jstack -l <pid>Code language: HTML, XML (xml)

Force a stack dump from a hung process

jstack -F <pid>Code language: HTML, XML (xml)

Print mixed Java/native frames

jstack -m <pid>
jstack -m <pid> | c++filtCode language: HTML, XML (xml)

In mixed-stack output, frames prefixed with an asterisk (*) are Java frames; non-prefixed frames are native C/C++ frames.

Read stacks from a core dump

jstack $JAVA_HOME/bin/java coreCode language: PHP (php)

As documented by Oracle, you can also get equivalent thread-dump output via Ctrl+\ on the console or by sending QUIT to the JVM process.

Troubleshooting workflow for hangs and deadlocks

flowchart TD
    A[Service appears hung] --> B[Find JVM pid]
    B --> C[Run jstack pid]
    C --> D{Command responds}
    D -- yes --> E[Run jstack -l pid]
    D -- no --> F[Run jstack -F pid]
    E --> G[Check deadlock section]
    F --> G
    G --> H[If needed run jstack -m pid]
    H --> I[Identify lock or native stall]
    I --> J[Apply fix and validate]

How to read key output signals quickly

  • Deadlock indicator: look for lines like Found one Java-level deadlock.
  • Lock ownership clues: lines stating one thread is waiting to lock an object held by another thread.
  • Thread state focus: prioritize BLOCKED, long WAITING, and repeating patterns across multiple dumps.
  • Mixed stack clues: use -m when the issue may involve JNI or VM-native code paths.

References

Best practices

  • Start with jstack -l for lock-aware analysis when investigating hangs.
  • If the process is unresponsive, use -F only when needed and note platform constraints.
  • Use -m when Java-only stacks do not explain the issue (native/JNI suspicion).
  • Keep a consistent incident runbook so thread dumps are captured quickly and repeatably.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Gerrit Performance Tuning Cheat Sheet: Workflow, Bottlenecks, and Practical Commands

A practical Gerrit performance guide for DevOps and platform engineers. Learn a repeatable tuning workflow, where bottlenecks usually appear, and which commands to run first.

Read More

Fix Jenkins java.lang.OutOfMemoryError: PermGen Space (Controller, Agents, and Build Tools)

Jenkins PermGen errors are usually caused by JVM memory limits set in the wrong place. This guide shows where to configure memory flags for controllers, agents, and build tools, plus how to handle Java 8+ where PermGen was replaced.

Read More

EMMA for Java Code Coverage: Setup, Instrumentation Modes, and J2EE Workflow

EMMA is a Java code coverage tool used to see which code paths are actually exercised by tests and runtime usage. This updated guide explains installation choices, instrumentation modes, and the offline J2EE workflow described in the original post.

Read More

ANT_OPTS in Apache Ant: JVM Memory, Proxy Settings, and Startup Troubleshooting

ANT_OPTS passes JVM options to the Java process that runs Ant. This guide explains how ANT_OPTS differs from ANT_ARGS and JAVACMD, with practical examples for memory tuning, proxy setup, and startup error diagnosis.

Read More

Embedded Jetty for Mission-Critical Production: Deployment Model, Trade-offs, and Operations

Running Jetty as an embedded server packages your app and runtime into one deployable artifact. This guide explains why teams use this model, how to deploy it, and what operational controls you must own.

Read More

What is Scala and use cases of Scala?

What is Scala? Scala is a general-purpose programming language that mixes object-oriented and functional programming paradigms. It was designed to be concise, elegant, and to integrate seamlessly…

Read More
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Puja kushwaha
Puja kushwaha
1 month ago

The jstack utility is especially helpful when a Java application hangs or shows slow response times. Taking several thread dumps a few seconds apart can reveal repeated blocked threads or deadlocks. It is useful to check thread states and look for lock conflicts before changing code. Pairing thread dumps with CPU and memory data can give a clearer picture of the issue. Always capture dumps safely on production systems to avoid adding unnecessary load.

1
0
Would love your thoughts, please comment.x
()
x