2.5K
In this tutorial, you’ll learn about Life cycle of a thread in Java, what are the states of Java thread like new, runnable, blocked, waiting and more.
The life cycle of a thread in java is controlled by JVM. A thread goes through various stages in its lifecycle. For example, a thread is born, started, runs, and then dies. The following diagram shows the complete life cycle of a thread.
Java Thread States
The java thread states are as follows:
- New
- Runnable
- Blocked
- Waiting
- Timed Waiting
- Terminated
- New − A new thread begins its life cycle in the new state. It remains in this state until the program starts the thread. It is also referred to as a born thread.
- Runnable − After a newly born thread is started, the thread becomes runnable. A thread in this state is considered to be either running or ready for execution but it’s waiting for resource allocation
- Blocked – waiting to acquire a monitor lock to enter or re-enter a synchronized block/method
- Waiting − Sometimes, a thread transitions to the waiting state while the thread waits for another thread to perform a task. Thread transitions back to the runnable state only when another thread signals the waiting thread to continue executing.
- Timed Waiting − Waiting for some other thread to perform a specific action for a specified period. A thread in this state transitions back to the runnable state when that time interval expires or when the event it is waiting for occurs.
- Terminated (Dead) − A runnable thread enters the terminated state when it completes its task or otherwise terminates.