Java Interview Questions

BY Author

Java – Thread Life Cycle

Thread started by JVMat the starting of a program is known as main thread or parent thread.And the threads created by the programmer are called child threads.Every thread has some different state from the moment of its creation till its death (termination).This process of getting different states at different situations is called life cycle of the thread.The life cycle of any thread in Java is as shown below:

New/Born Thread

The thread created by a programmer using newoperator before invoking the start() method on it is called new/born thread.

Runnable Thread

Runnable means, capable of running/execution.

After invoking the start()method by a thread and before getting it selected by thread scheduler for execution, the thread is in a runnable state. At this stage, it is ready to get executed as soon as it gets a chance by thread scheduler.

Running Thread

When the thread starts its execution after getting it selected by thread scheduler is said to be in running state.

Blocked Thread

The blocked state contains sleepingstate, waitingstate, suspendedstate, etc.The thread may enter into any of these states when it is in the blocked state. It depends on the function invoked by a thread or the condition of the program.Here the working of a thread is stopped temporarily and not permanently.

Dead Thread

When work of thread gets over, that is when it completes run()method, the thread enters into dead state. That is JVMterminates the thread.

Here, it may find difficult to understand the complete life cycle of a thread.But as we will step forward to learn multithreading in detail, it will be understood very easily.