This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
The following is the life cycle of a thread after invoking a start method using Thread object.
1) runnable 2) running 3) non-runnable(sleep/wait/yield) 4) dead
yield ---> when a thread calls this method it steps back to to to a non runnable the other threads having same priority or higher than the current thread are given chance to go into running state. This is arbitrary it is quite possible that a thread might go to a non runnable state and the same thread comes to runnable state and then directly go to running state without giving chance to other threads (of same priority). Please remember, yield is a static method.
sleep ---> Sleep will put a current running thread to sleep for a millisecond defined in its argument list (eg: sleep(1000) implies 1000 millisecond). This method will put the current thread into non runnable state. the thread can be back to runnable state after the time elapsed to it gets over. sleep is static method belong to Thread class.
OS is mostly responsible for scheduling threads to run, till what time etc... If i guess right Windows implements time-slicing and linux schedules according to thread priorities. [ February 15, 2007: Message edited by: Atul Savant ]