---
title: "Describe the life cycle of a thread in Java."  
description: "Describe the life cycle of a thread in Java."  
author: "Anubhav Sharma"  
published: 2024-07-18  
updated: 2024-07-18  
canonical: https://www.mindstick.com/forum/160947/describe-the-life-cycle-of-a-thread-in-java  
category: "java"  
tags: ["java", "javac"]  
reading_time: 3 minutes  

---

# Describe the life cycle of a thread in Java.

[Describe the life](https://answers.mindstick.com/qa/101503/describe-the-life-of-cleopatra-the-egyptian-queen) [cycle](https://yourviews.mindstick.com/view/81850/possible-effects-of-solar-weather-cycle) of a thread in Java.

## Replies

### Reply by Ravi Vishwakarma

In Java, a thread goes through several states during its [life cycle](https://www.mindstick.com/articles/23194/the-life-cycle-of-software-development). These states represent the different stages a thread can be in from its creation to its termination.

Here is a detailed explanation of the life cycle of a thread in Java:

![Describe the life cycle of a thread in Java.](https://www.mindstick.com/mindstickforums/ec2c6f17-f1a3-4f52-a1f3-88867c07d36d/images/6c3bf5e3-f8a6-4c85-9827-96eddd302fa7.png)

#### 1. New

- **State:** `NEW`
- **Description:** A thread is in the `NEW` state when it is created but not yet started. At this point, the thread has been instantiated, but the `start()` the method has not been called.

```java
Thread thread = new Thread(() -> {
    // Task to perform
});
```

#### 2. Runnable

- **State:** `RUNNABLE`
- **Description:** A thread enters the `RUNNABLE` state when the `start()` the method is called. In this state, the thread is ready to run and waiting for CPU time. It is also the state where the thread executes its task. However, due to time-sharing and the thread scheduler, a thread in the `RUNNABLE` the state may not be actively running.

```java
thread.start(); // Thread transitions to RUNNABLE state
```

#### 3. Blocked

- **State:** `BLOCKED`
- **Description:** A thread enters the `BLOCKED` state when it attempts to access a synchronized block or method that is currently locked by another thread. The thread remains in this state until the lock is released.

```java
synchronized (someObject) {
    // Thread may become BLOCKED if another thread holds the lock
}
```

#### Waiting

- **State:** `WAITING`
- **Description:** A thread enters the `WAITING` state when it is waiting indefinitely for another thread to perform a particular action. This happens when the thread calls methods like `Object.wait()` without a timeout, `Thread.join()` without a timeout, or `LockSupport.park()`.

```java
synchronized (someObject) {
    someObject.wait(); // Thread enters WAITING state
}
```

#### Timed Waiting

- **State:** `TIMED_WAITING`
- **Description:** A thread enters the `TIMED_WAITING` state when it is waiting for a specified period. This can happen when the thread calls methods like `Thread.sleep(long millis)`, `Object.wait(long timeout)`, `Thread.join(long millis)`, or `LockSupport.parkNanos(long nanos)`.

```java
try {
    Thread.sleep(1000); // Thread enters TIMED_WAITING state for 1 second
} catch (InterruptedException e) {
    e.printStackTrace();
}
```

#### Terminated

- **State:** `TERMINATED`
- **Description:** A thread enters the `TERMINATED` state when it has finished executing. This can happen either because the thread's `run()` the method has been completed, or because an uncaught exception has terminated the thread.

```java
// After the run() method completes
```

## Thread Life Cycle Diagram

```plaintext
NEW -> RUNNABLE <--> BLOCKED
         |           |       |
         V           V       V
    WAITING      TIMED_WAITING
         |
         V
    TERMINATED
```

## Summary of Transitions

- **NEW to RUNNABLE:** When `start()` is called.
- **RUNNABLE to BLOCKED:** When a thread tries to acquire a lock held by another thread.
- **RUNNABLE to WAITING:** When `Object.wait()`, `Thread.join()`, or `LockSupport.park()` is called.
- **RUNNABLE to TIMED_WAITING:** When `Thread.sleep(long)`, `Object.wait(long)`, `Thread.join(long)`, or `LockSupport.parkNanos(long)` is called.
- **WAITING to RUNNABLE:** When `Object.notify()`, `Object.notifyAll()`, or the corresponding event occurs.
- **TIMED_WAITING to RUNNABLE:** When the specified waiting time elapses.
- **BLOCKED to RUNNABLE:** When the thread acquires the lock.
- **RUNNABLE to TERMINATED:** When the thread's `run()` method completes or an uncaught exception terminates the thread.

## Read more

[**Explain the difference between checked and unchecked exceptions. Provide examples.**](https://www.mindstick.com/forum/160948/explain-the-difference-between-checked-and-unchecked-exceptions-provide-examples)

[**What are annotations in Java? How are they used?**](https://www.mindstick.com/forum/160949/what-are-annotations-in-java-how-are-they-used)

[**What is the purpose of the volatile keyword in Java?**](https://www.mindstick.com/forum/160950/what-is-the-purpose-of-the-volatile-keyword-in-java)


---

Original Source: https://www.mindstick.com/forum/160947/describe-the-life-cycle-of-a-thread-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
