• Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread.sleep(0)  RSS feed

 
Drew Lane
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you expect to gain with this extra logic?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!