Life cycle of a Thread

Category: General Question    |    115 views

Threads can be in one of four states:

1)start or new
2)runnable
3)blocked
4)dead

1)Start or new:

When you create a thread ,the thread is not yet running.This means that
it is in the new state.It is just in start state.Java has not started executing code inside of this state.A certain  amount of  booking needs to be done before a thead can run.

2)Runnable:

once you start the thread,the thread is runnable.A runnable thread may
not yet be running.It is up to the operating system to give it time to do so.when the code inside the thread begins executing ,the thread is
running.Arunning thread si still in the runnable state.

Note:A runnable thread may or may not be running at any given time.

3)Blocked:

The thread enters the blocked state when one of the following actions occurs:

a)Someone calls the sleep() method of the thread.
b)The thread calls the wait() method.
c)the Thread calls an operations that is blocked on input/output,that is ,an operation that will not return to ti caller until input and output operation are complete.
d)when a thread is waiting for any resource.

4)Dead:

A thread is dead for one of two reasons.
a)It dies a natural dealth because the thread completes its execution.
b)It is killed because someone invoked its stop method.

Share/Save/Bookmark

1 Star2 Stars
Loading ... Loading ...

2 responses so far!

Leave a Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word