Briefly explain the Thread Life cycle.
In its lifecycle, a thread goes through several stages. A thread, for example, gets born, starts, runs and eventually dies.
The following are the stages of the thread's lifecycle.
New- In the new state, a new thread begins its life cycle. It will stay in this state until the thread is started by the program. A born thread is another name for it.
Runnable- When a freshly created thread is initiated, it becomes runnable. When a thread is in this position, it is regarded to be doing its job.
Waiting- When a thread is waiting for another thread to complete a job, it may shift to the waiting state. Only when another thread signals the waiting thread to continue executing does the thread transition back to the runnable state.
Timed Waiting- A runnable thread can go into a timed waiting state for a set amount of time. When the period expires or the event it is waiting for occurs, a thread in this state moves back to the runnable state.
Terminated (Dead) -
When a runnable thread completes its task or otherwise terminates, it enters the terminated state.
Comments
Leave a comment