• 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

what's diff between Thread.sleep() and Thread.current.sleep() ??

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx!
 
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Two things:
First, Thread.current.sleep() will not compile! There is no 'current' symbol/variable/member/attribute (or any other fancy term) in the Thread class. I assume that you meant Thread.currentThread().sleep().
Now, the answer is: There is no difference.
But the sencond thing is, this is not an issue of threads or even the Thread class it has to do with simple Java.
The sleep() method as well as the currentThread() are static. When using the sleep method directly, you cause the current thread to sleep. Now, if you do your thing with the currentThread() you are just doing extra work.
Consider this:

One note on threading: You cannot put thread A to sleep from thread B.
Leslie
 
Javan Li
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx very much. you are great help.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic