Wednesday, March 28, 2007

Ways the Threads leaving Running State

The ways by which a running thread could leave the running state :

1.When a sleep() method is called.
2.When a yield() method is called.
3.When a join() method is called.
4.When a wait() method is called.
5.When the run() method is completed.
6.When its blocked ,waiting for some resources.
7.When the Thread Scheduler Schedules the Threads.

* A call to sleep() Guaranteed to cause the current thread to stop executing for at least the specified sleep duration (although it might be interrupted before its specified time).

* A call to yield() Not guaranteed to do much of anything, although typically it will cause the currently running thread to move back to runnable so that a thread of the same priority can have a chance.

* A call to join() Guaranteed to cause the current thread to stop executing until the thread it joins with (in other words, the thread it calls join() on) completes, or if the thread it's trying to join with is not alive, however, the current thread won't need to back out.

No comments: