aspose file tools
The moose likes Threads and Synchronization and the fly likes Thread.sleep(0) Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Thread.sleep(0)" Watch "Thread.sleep(0)" New topic
Author

Thread.sleep(0)

Drew Lane
Ranch Hand

Joined: May 13, 2001
Posts: 296
Is there any performance penalty by calling Thread.sleep(0)?
I've got a program that lets the user define the wait period between animation frames and I'm wondering if it would be better to just bypass sleep() altogether if they select zero.
Thanks,
Drew
Leslie Chaim
Ranch Hand

Joined: May 22, 2002
Posts: 336
What do you expect to gain with this extra logic?


Normal is in the eye of the beholder
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18652
Is there any performance penalty by calling Thread.sleep(0)?
Well, it takes a tiny bit longer than not calling any method. It probably behaves like a Thread.yield() - it 's not guaranteed to have any effect, but it creates an opportunity for any other waiting threads to run. (Which they could do anyway if the JVM feels like it.) I suspect that it really doesn't matter much whether you put in extra logic to avoid calling sleep(0) - so I wouldn't bother unless you find that there's a problem.


"I'm not back." - Bill Harding, Twister
 
IntelliJ Java IDE
 
subject: Thread.sleep(0)
 
Threads others viewed
WA #1.....word association
Help with Thread.sleep()
Question regarding Synchronized(anObject)
Setting Up A Delay Between E-mail tranmissions
Timer/ TimerTask
developer file tools