1.

Thread Life Cycle in Java

Answer»

The Thread Life Cycle in Java contains 5 states. This means that the thread can be in any of these 5 states. A diagram to understand the states in the thread life cycle is GIVEN below:

The 5 states in a thread life cycle are:

  • New

When an instance of the thread class has been created but the start() method is not invoked, then the thread is in the new state.

  • Runnable

When the start() method has been invoked but the thread scheduler has not selected the thread for execution, then the thread is in the runnable state.

  • Running

If the thread scheduler has selected a thread and it is CURRENTLY running, then it is in the running state.

  • Blocked (Non-runnable)

When a thread is not ELIGIBLE to run but still ALIVE, then it is in the blocked state.

  • Terminated

When the run() method of a thread exits, then it is in the terminated state.



Discussion

No Comment Found