SEMrush

Threads

What is a Thread?
           
Thread is a lightweight sub-process, a smallest unit of processing.
Thread Class contains run() method, which has the actual work to be performed by thread.

Life cycle of a thread

The life cycle of the thread contains following 5 stages:
1.      New
2.      Runnable
3.      Running
4.      Non-Runnable (Blocked)
5.      Terminated

1) New
The thread is in new state if you create an instance of Thread class but before the invocation of start() method.
2) Runnable
After invocation of start() method, but the thread scheduler has not yet selected it to run.

3) Running
When the thread scheduler has selected the thread, the thread is in running state .

4) Non-Runnable (Blocked)
When the thread is alive, but is currently not eligible to run, it is in blocked state

5) Terminated
When its run() method exits the thread attains terminated or dead state





Comments