Gurgaon Jobs, Companies and Consultants

Those who are looking for job in Gurgaon can visit this site : Gurgaon Jobs. Here you will find email ids/contact no of "Companies in Gurgaon" and also of "Placement Consultants in Gurgaon"

Wednesday, April 08, 2009

Java Thread : yield() Versus sleep(n)

If you call sleep(n), the sleeping thread will do nothing for that duration of the sleep. If no other thread wants CPU, then the CPU will remain idle.

if no other thread waiting, in case of sleep it is guaranteed that CPU will be idle for given time .

In contrast, if you call yield() , the yielding thread will carry on processing almost straight away
only if
no other thread wants CPU.

if no other thread waiting, in case of yield CPU will be in use same thread will continue processing.

No comments: