Life Cycle Of A Thread
Thread life cycle
A thread goes through many different stages in its life cycle. For example, a thread is born, thread starts, thread runs and then thread dies. The life cycle of the thread is controlled by JVM in Java. For better understanding of the threads, we explain it in the five states, given below.
- New
A new state is the first state of the thread. The thread is in new state, if we create an object of the thread class but before the invocation of start () method. - Runnable
After a new thread starts, the thread is in second state after invocation of start () method, but the scheduler has not selected it to be in the running thread. - Running
The third state is running. The thread is in running state, if the thread scheduler has selected it. - Non-Runnable (Blocked)
The fourth state is non-runnable (blocked). This is the state, when the thread is alive, but is currently not eligible to run. - Terminated
Last state is terminated. A thread is in terminated state, when its run () method exits.
Summary
Thus, we learnt, the life cycle of the thread is controlled by JVM in Java and also learnt its five states of life cycle.