100% found this document useful (1 vote)
2K views2 pages

Life Cycle of A Thread

A thread can be in one of five states during its lifecycle: 1) Newborn state: A newly created thread that has not been started yet. 2) Runnable state: A thread that is ready to execute but not currently running. 3) Running state: The thread is currently executing and occupies the CPU. 4) Blocked state: The running thread is waiting for a specific condition, like I/O. 5) Terminated state: The thread has completed its task and ended its lifecycle.

Uploaded by

rajuvathari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
2K views2 pages

Life Cycle of A Thread

A thread can be in one of five states during its lifecycle: 1) Newborn state: A newly created thread that has not been started yet. 2) Runnable state: A thread that is ready to execute but not currently running. 3) Running state: The thread is currently executing and occupies the CPU. 4) Blocked state: The running thread is waiting for a specific condition, like I/O. 5) Terminated state: The thread has completed its task and ended its lifecycle.

Uploaded by

rajuvathari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Life cycle of a Thread (Thread States)

A thread can be in one of the five states. The life cycle of the thread in java is controlled by
JVM. The java thread states are as follows:

1. Newborn
2. Runnable
3. Running
4. Non-Runnable (Blocked)
5. Terminated

1) Newborn state:
When we create the thread object, the thread is born and is said to be in newborn
state. The thread is ready to execute not running. At this state we can do only one of the
following things with it.

 Ready for running using start( ) method.


 Kill it using stop( ) method.

MyThread t= new MyThrtead()  Newborn state


In this state, system resources are not yet allocated to the thread. When a thread is in the
newborn state, calling any method other than start() method causes an
IllegalThreadStateException.

2) Runnable state:
A thread in the runnable state is ready for execution but is not being executed
currently. Once a thread is in the runnable state, it gets all the resources of the system (as, for
example, access to the CPU) and moves on to the running state.

All runnable threads are in a queue and wait for CPU access. When the start( ) method is
called on the newborn thread, it will be in the runnable state.

3) Running state:
After If thread scheduler allocates CPU for particular thread. Thread goes to running
state. The Thread is running state means the run( ) is executed.

Running state:

4) Blocked state:
If the running thread got interrupted of goes to sleeping state at that moment it goes to
the blocked state.

5) Terminate state:
Every thread has a life cycle. A running thread ends its life when it has completed
executing its run( ) method. It is a natural death. However, we can it by sending the stop
message to it at any state this causing a premature death to it. A thread can be killed as soon
as it is born, or while it is running or even when it is in blocked state.

You might also like