Java Multitasking  «Prev  Next»

Lesson 7 Modern Java Thread Lifecycle
Objective Understand the six official thread states in the modern Java Virtual Machine (JVM)

Java Thread Life Cycle

The Java platform provides a powerful, high-level concurrency model that abstracts most operating system–level scheduling details. While early versions of Java (such as 1.1) described five conceptual thread states—new, runnable, running, blocked, and terminated—modern Java defines six precise states in the Thread.State enumeration. These states are consistent across JVM implementations and provide a unified model for both traditional platform threads and lightweight virtual threads introduced in Java 19.

The Six Modern Thread States

  1. NEW: The thread has been created, but its start() method has not yet been invoked. No system resources are yet allocated for execution.
  2. RUNNABLE: The thread is eligible to run and may be executing on a CPU or waiting in the operating system’s ready queue. Unlike in Java 1.1, the JVM no longer distinguishes between “ready” and “running.” Threads blocked in native I/O (such as Socket.read()) are often still reported as RUNNABLE.
  3. BLOCKED: The thread is waiting to acquire a monitor lock so it can enter a synchronized block or method. Once the lock becomes available, the thread transitions back to RUNNABLE.
  4. WAITING: The thread is waiting indefinitely for another thread to perform a specific action. Common examples include calls to Object.wait() (without a timeout), Thread.join() (without timeout), or LockSupport.park().
  5. TIMED_WAITING: The thread is waiting for a specified amount of time. Typical entry points include Thread.sleep(ms), Object.wait(ms), Thread.join(ms), and LockSupport.parkNanos(). After the timeout or notification, the thread transitions back to RUNNABLE.
  6. TERMINATED: The thread has finished execution—either because the run() method completed normally or due to an uncaught exception. Once terminated, a thread cannot be restarted.

Transition Mechanisms

Threads move between these states through specific methods and events:

Deprecated and Unsafe Methods

Early threading models included methods like stop(), suspend(), and resume(). These were removed in modern Java because they could lead to deadlocks and data corruption. Instead, developers should use interruption (Thread.interrupt()), concurrency utilities (such as java.util.concurrent), or explicit signaling through LockSupport.


Thread States Visualization

Thread States in a Nutshell
Modern thread state transitions in Java

Summary

Modern Java provides a clean, standard model of thread behavior that aligns with both traditional OS threads and the new virtual thread framework. By understanding these six states, developers can reason more effectively about concurrency, synchronization, and performance in multi-threaded applications.


SEMrush Software