wood burning stoves
The moose likes Threads and Synchronization and the fly likes Sleep or Yield in a infinite loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Sleep or Yield in a infinite loop" Watch "Sleep or Yield in a infinite loop" New topic

Sleep or Yield in a infinite loop


Joined: Sep 11, 2001
Posts: 1
Sleep or Yield in a infinite loop
I need to code an infinite loop. What is the best way to pause
the thread for a while.
Sleep : The thread would go to the "sleep" state for the specified amount of time.
Yield: The thread would move from running state to ready state

//do something
Does yield have any problem in a preemptive scheduling system.(like NT)
Andrew Trumper

Joined: Sep 08, 2001
Posts: 12
In my experience sleep is the way to go. The yeild loops I've coded tend to be huge processor hogs. I've had to replace them all in the program I've been developing.
The sleep value should be significantly large as well. 1 sec or more.... if possible of course.
Marcela Blei
Ranch Hand

Joined: Jun 28, 2000
Posts: 477
your name is not valid as per the Javaranch name conventions. Please refer to the document located here
I agree. Here's the link: http://aspose.com/file-tools
subject: Sleep or Yield in a infinite loop
It's not a secret anymore!