Fundamentals 6 min read

Java Thread States and How to Query Them

This article explains Java’s six thread states—NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING, and TERMINATED—provides detailed descriptions, shows how to inspect thread states using jstack and online tools, and includes example thread dumps for practical analysis.

Cognitive Technology Team
Cognitive Technology Team
Cognitive Technology Team
Java Thread States and How to Query Them

Java Thread States

Java defines six thread states that a java.lang.Thread can be in during its lifecycle: NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING, and TERMINATED.

NEW – The thread has been created but not yet started (the constructor has been called but Thread.start() has not). A thread in this state has not yet begun execution.

RUNNABLE – The thread is executing in the JVM or is ready to run and waiting for CPU time from the operating system. It may be actively using CPU or be queued for scheduling.

BLOCKED – The thread is waiting to acquire a monitor lock to enter a synchronized block or method, or to re‑enter after calling Object.wait() .

WAITING – The thread is waiting indefinitely for another thread to perform a specific action, such as Object.wait() without a timeout, Thread.join() without a timeout, or LockSupport.park() .

TIMED_WAITING – The thread is waiting for a specified period, caused by calls such as Thread.sleep() , Object.wait(long) , Thread.join(long) , LockSupport.parkNanos() , or LockSupport.parkUntil() .

TERMINATED – The thread has completed execution and is dead.

How to Query Thread State

1. Using the jstack command

jstack -l <pid> > <file-path>

Example output (truncated) shows each thread’s name, ID, and state:

"Reference Handler" #2 daemon prio=10 os_prio=31 cpu=132.66ms elapsed=14508.18s nid=0x3e03 waiting on condition  [0x0000700008111000]
   java.lang.Thread.State: RUNNABLE
   at java.lang.ref.Reference.waitForReferencePendingList(Native Method)
   ...
"C2 CompilerThread0" #6 daemon prio=9 os_prio=31 cpu=165892.13ms elapsed=14508.16s nid=0xa503 waiting on condition  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE
   ...

2. Online tool: fastthread.io

Visit https://fastthread.io and paste a thread dump to get a visual representation of thread states.

3. Spotify Thread‑Dump Analyzer

Another web‑based analyzer is available at https://spotify.github.io/threaddump-analyzer/ , which parses the dump and displays state distribution.

Summary

Understanding the six Java thread states helps developers diagnose issues such as deadlocks, thread‑starvation, or excessive waiting. By using jstack or online analyzers, you can quickly identify the current state of each thread, assess utilization, and make informed decisions about thread pool sizing and synchronization strategies.

JavaconcurrencythreadThread Statesjstack
Cognitive Technology Team
Written by

Cognitive Technology Team

Cognitive Technology Team regularly delivers the latest IT news, original content, programming tutorials and experience sharing, with daily perks awaiting you.

0 followers
Reader feedback

How this landed with the community

login 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.