• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Javan Li
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx!
 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanx very much. you are great help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!