Wednesday, March 28, 2007

Thread States

The Life cycle or States of Threads.

1.New
2.Runnable
3.Running
4.Sleeping/waiting/blocked (Not Runnable)
5.Dead

Once the start() method is called, the thread is considered to be alive . A thread is considered dead after the run() method completes.

The isAlive() method is the best way to determine if a thread has been started but has not yet completed its run() method.

New state - when Thread is instantiated , but before the start method is invoked.

Runnable state - when the start method is invoked , and its ready to execution

Running state - This is where the action takes place.

Not Runnable state - This is where , the Thread is still alive ,but not eligible to run.A thread arrives at this state ,when it is blocked waiting for a resource like I/O , or when the sleep method is called or when the wait method is called.

Dead state - A thread is considered dead when its run() method completes.

No comments: