Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Sleep method - Native

 
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Adam. It solves my purpose.
 
reply
    Bookmark Topic Watch Topic
  • New Topic