| Author |
Synchronization
|
rupika deval
Greenhorn
Joined: Jan 04, 2008
Posts: 6
|
|
|
What is an yield() method? and how is it different from sleep() and wait()
|
 |
Lave Kulshreshtha
Ranch Hand
Joined: Oct 21, 2007
Posts: 106
|
|
Yield relinquish the CPU but sleep does not. Sleep takes sleep time as input. -Lave
|
SCJP 1.4, SCWCD 1.4, SCBCD 1.3, ITIL V3 Foundation Certification
|
 |
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
|
|
[Lave]: Yield relinquish the CPU but sleep does not. Where did you get this idea? That's not even remotely true. Either method may relinquish the CPU, while neither is required to. The sleep() method is more likely to relinquish the CPU, because it generally has a minimum time span during which it cannot resume control of the CPU. Unless you're calling sleep(0), which is generally equivalent to yield().
|
"I'm not back." - Bill Harding, Twister
|
 |
Lave Kulshreshtha
Ranch Hand
Joined: Oct 21, 2007
Posts: 106
|
|
In one of my java projects it happend, the sleep was consuming CPU continuosly, so I used yield along with sleep to get rid of this problem. -Lave
Originally posted by Jim Yingst: [QB][Lave]: Yield relinquish the CPU but sleep does not. Where did you get this idea? QB]
|
 |
Adeel Ansari
Ranch Hand
Joined: Aug 15, 2004
Posts: 2874
|
|
|
Similar thread
|
 |
 |
|
|
subject: Synchronization
|
|
|