Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Native methods in Java

Tags:

java

I have spent some time learning what are Java Native methods and that they are implemented in platform dependent code(mostly C).

But where can I find those native implementations of Java? eg : sleep(long millis) method of Thread class is native. But where is its implementation code???

like image 714
killerCoder Avatar asked Jul 02 '11 13:07

killerCoder


2 Answers

The native code is implemented within the JVM (Java Virtual Machine). The Java developer isn't supposed to worry about their implementation as they relate to the inner working of the virtual machine. However, you can write your own native methods using JNI or see how they are implemented for a specific JVM.

like image 151
Jihed Amine Avatar answered Sep 27 '22 19:09

Jihed Amine


But where can I find those native implementations of Java?

You'll have to download the complete source of some JDK. In OpenJDK for instance, you'll find lots of files related to threads:

./jdk/src/share/native/java/lang/Thread.c
like image 42
aioobe Avatar answered Sep 27 '22 20:09

aioobe