Life cycle of Thread:
- Every thread executes according to Life cycle.
- Life cycle consists
- Creation phase by programmer
- Execution phase by scheduler(OS)
- As a programmer, we need to define and start the thread.
- All threads scheduled by the processor.
- Thread has many states
- Runnable state
- Running state
- Waiting state
- Dead state.
- Every thread should wait in the Queue until processor allocates the memory is called Runnable state.
- Once the memory has been allocated to thread, it moves to running state. In running state, thread execute independently.
- From the running state, the thread may fall into waiting state to read user input, sleep and join methods.
- Once the thread execution completed, it moves to dead state.