Explain the thread lifecycle in Java?

There are 5 states in a thread lifecycle and java can be at any one of them. The thread lies in any one of these states:

  • New: The thread lies in the new state after it has been created. It remains in the new state until you start the execution process.
  • Running: At runnable state, the thread is ready to run at any point in time or it might have started running already.
  • Running: The scheduler picks up the thread and changes its state to running, the CPU starts executing the thread in the running state.
  • Waiting: While being ready to execute, another thread might be running in the system. So, the thread goes to the waiting state.
  • Dead: Once the execution of the thread is finished, its state is changed to the dead state, which means it’s not considered active anymore.