• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thread.sleep(0)

 
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you expect to gain with this extra logic?
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic