Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Sleep method - Native  RSS feed

 
Patricia Samuel
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

I am little confused or can say not clear at all about

Why we do have native method in class Thread and that too
One Sleep method has following prototype
public static native void sleep(long millis) throws InterruptedException;


and another has following-
public static void sleep(long millis, int nanos)
throws InterruptedException ;


So what is the purpose behind this choice.... I know it could be a lame question but curious to know....

Any help.

Regards,
Patricia.
 
Adam Michalik
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thread.sleep(long) is native because it is mapped directly onto the underlying operating system's thread management (ie. on Windows it behaves differently than on Linux or Solaris or any other system). Thread.sleep(long, int) is not native, because id does some internal logic in Java and then calls Thread.sleep(long). See the source code for details.
 
Patricia Samuel
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Adam. It solves my purpose.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!