Life cycle of a thread in Java

275 views

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.

Life cycle of a thread in Java
Life cycle of a thread in Java

The java thread states are as follows:

  1. New
  2. Runnable
  3. Blocked
  4. Waiting
  5. Timed Waiting
  6. 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.

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Enable Notifications    OK No thanks