File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Synchronization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Synchronization" Watch "Synchronization" New topic
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: 18671
[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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Synchronization