Wednesday, January 26, 2011

Thread.yeild() Vs Thread.Sleep() in java

I tried to find out this diff, bt no where its clearry given. All the details i found was jst bookies thing.
Finally i found this good answer, hope this will help you as well:-
yeild() : This allows other threads to execute which are in Runnable state and Our thread will also go in Runnable state. So that CPU Scheduler may choose other Thread from runnable pool torun . It may choose our thread too. Its not guranteed...
Sleep(): On call of this Our Thread goes to waiting state for specified time. So it gurantees that till that specified time CPU will not pick our thread. After time expires, it will be to Runnable State. Now it will be part of CPU allocation.

No comments:

Post a Comment