Thread Lifecycle in Java
In the Java programming language, the thread lifecycle allows user-defined custom thread states to indicate the completion stage of a task. A custom thread can process and wait from design development to execution termination.

The Java language provides its users with the Thread class to create and manage a thread. Remember, a thread in Java does not remain static in a single state throughout its lifecycle. It automatically moves from one state to another based on its set execution method and actions taken by the JVM or operating system.
Java provides its users with six official thread states through the Thread.State enum.
- NEW thread state
- RUNNABLE thread state
- BLOCKED thread state
- WAITING thread state
- TIMED_WAITING thread state
- TERMINATED thread state
NEW java thread state.
In a Java program, when a new thread object is created by the user, but its start() function method has not yet been called, the thread is defined in the NEW state.
Example of the NEW Java thread state.
class SampleThread extends Thread {
public void run() {
System.out.println(“New Thread is continuing”);
}
}
public class Main {
public static void main(String[] args) {
SampleThread th1 = new SampleThread();
// Here th1 is in the NEW thread state defined
}
}
Here in the NEW Java thread state example.
SampleThread th1 = new SampleThread();
In this example, when a thread object is created, but the Thread class has not yet called its execution method, it is defined in the NEW state.
So here in this.
NEW → start() → RUNNABLE
RUNNABLE Java thread state.
When the start() function method is called in a Java thread program, the user-defined thread automatically moves into the RUNNABLE state.
th1.start();
In this state, your thread is now eligible to run. The operating system/JVM scheduler installed in your system determines when it receives processing time in real-time microprocessor CPU cycles.
Example of RUNNABLE Java thread state.
class SampleThread extends Thread {
public void run() {
System.out.println(“Thread is continuing”);
}
}
public class Main {
public static void main(String[] args) {
SampleThread th1 = new SampleThread();
th1.start();
}
}
Key points about RUNNABLE Java thread state.
In this Java program, the RUNNABLE thread state includes both tasks being ready to run and, conceptually, actively running. There is no separate official RUNNING state in Java’s Thread.State.
BLOCKED Java thread state.
A custom thread in a Java program enters or moves into the BLOCKED thread state when it is waiting to acquire a monitor lock.
This Java thread state is executed when another thread has already entered a synchronized block or method using the same object lock.
Example of BLOCKED Java thread state.
class SampleTask {
synchronized void display() {
try {
Thread.sleep(3000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
Here, assume that a thread in this state is already executing the display() function. If another thread forces it to enter the same synchronized method, it may enter or move into the BLOCKED state until the lock becomes available in the thread state.
Basic thread blocking concept.
Thread X → This thread holds the lock on the task process.
Thread Y → This thread tries to acquire the lock on the task process.
↓
Blocked thread state.
After the lock becomes available in this thread, thread Y moves back to RUNNABLE.
Waiting Java thread state.
In a Java program, a thread lifecycle moves into the WAITING state when it waits for a long time for another thread task in the current state to perform some action.
Example of the WAITING Java thread state.
th1.join();
This thread waits until the calling thread th1 method terminates.
Other thread operations that can cause the thread to be in a waiting state include:
- Object.wait()
- Thread.join() without a timeout
- LockSupport.park()
Example of a waiting Java thread.
Thread th1 = new Thread(() -> {
System.out.println(“task thread”);
});
th1.start();
try {
th1.join();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
Here, the thread calling the join() function method in the thread process waits for th1 to terminate.
TIMED_WAITING Java thread state.
A user-defined custom thread in a Java program enters the TIMED_WAITING state when it waits for a task in its timeline for a specified amount of time.
Example of the TIMED_WAITING Java thread state.
Thread.sleep(4000);
Here, your current thread waits for a minimum of 4 seconds.
Other thread timed waiting examples include.
th1.join(4000);
and so forth.
object.wait(4000);
Example of a TIMED_WAITING Java thread.
class SampleThread extends Thread {
public void run() {
try {
Thread.sleep(4000);
System.out.println(“Sample Thread pause”);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
Here, during the sleep() function method timeout period in the thread, the thread is in the TIMED_WAITING state.
After the thread’s task wait time expires, it can return to the RUNNABLE state.
Terminated Java thread state.
A thread in a Java program is displayed in the terminated state when its run() function method automatically terminates execution.
Example of a terminated Java thread state.
class SampleThread extends Thread {
public void run() {
System.out.println(“Thread is performing”);
}
}
public class Main {
public static void main(String[] args) {
SampleThread th1 = new SampleThread();
th1.start();
try {
th1.join();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
System.out.println(th1.getState());
}
}
Here, after the run() function method completes, the thread is automatically terminated.
After this, the terminated thread cannot be restarted.
th1.start(); // Display IllegalThreadStateException if th1 has already terminated.
Diagram of a basic thread lifecycle in a Java program.
First, a Thread object is created.
|
v
+———+
| Creating a new thread |
+———+
|
start() method
|
v
+————-+
| Runnable Thread State |
+————-+
/ | \
/ | \
v v v
Blocked Waiting TIMED_WAITING Thread State
| | |
| | |
+———+———-+
|
v
Runnable Thread State
|
|
The run() method terminates.
|
V
+————+
| Thread terminated |
+————+
Complete thread lifecycle example in Java.
class SampleThread extends Thread {
public void run() {
System.out.println(“Thread is continuing”);
try {
Thread.sleep(3000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
System.out.println(“Java Thread Terminated”);
}
}
public class Main {
public static void main(String[] args) {
SampleThread th1 = new SampleThread();
System.out.println(th1.getState()); //here it NEW thread state started
th1.start();
System.out.println(th1.getState()); // Here RUNNABLE or possibly another thread state mode
try {
th1.join();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
System.out.println(th1.getState()); // Here java thread finally TERMINATED
}
}
In this example, the exact state printed immediately after the start() function method may be different, as thread scheduling is controlled or managed by the JVM/OS.
Multiple Java Thread States Detail Explanation
| # | Multiple Thread State | Each Thread State Meaning |
| 1. | NEW State | In this state the new thread object created but start() function is not called during process |
| 2. | RUNNABLE State | In this state thread is ready to run or running state, it means your created thread ready for run |
| 3. | BLOCKED State | In this state user define thread is in waiting to acquire a monitor to lock its process |
| 4. | WAITING State | In this state thread waiting indefinitely for another thread/action to perform |
| 5. | TIMED_WAITING State | In this state thread is waiting for a specified amount of time to complete thread task |
| 6. | TERMINATED State | In this state finally thread has completed its execution process |
Thread States Summary in Thread Lifecycle.
There’s an easy way to remember the thread lifecycle in Java programming.
You can think of a thread state like an employee in a company.
- NEW State → In this thread state, a new employee has registered but hasn’t started yet.
- RUNNABLE State → In this thread state, the employee is ready and is actively working.
- BLOCKED State → In this thread state, the employee is waiting for a resource/lock method.
- WAITING State → In this thread state, the employee is waiting for a task for an indefinite period of time.
- TIMED_WAITING State → In this thread state, the employee is taking a break for a fixed period of time.
- TERMINATED State → In this thread state, the employee has completed all its tasks.
Conclusion of Thread Lifecycle in Java.
In the Java programming language, the thread lifecycle is a sequence of multiple individual steps (sequence states) that each user-defined custom thread moves through during its execution. In which all thread tasks start from a NEW state, RUNNABLE, then move through multiple states like BLOCKED, WAITING, or TIMED_WAITING, and finally achieve the TERMINATED thread state when the execution of that thread state is complete.

