I am looking for some in-depth explanation How Thread.start() internally invokes run() method. I know that its my JVM which internally calls run() via start() method and when I started checking the source code of Thread class, I found these below code:
public synchronized void start()
{
if(threadStatus != 0)
throw new IllegalThreadStateException();
group.add(this);
start0();
if(stopBeforeStart)
stop0(throwableFromStop);
}
private native void start0();
Now as I can see that the start() is calling the native method start0() but I can not see any code related to the loading of native code library.
Please help me understanding the complete call flow.
Thanks, Sandip
Java is open source.. A small research can bring you the source code of the native code also. See, you can see yourself the flow. See Where to find source code for java.lang native methods?.
According to: Java native method source code use jdk7 source
JDK 7's Thread.c: http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/00cd9dc3c2b5/src/share/native/java/lang/Thread.c
Per my knowledge, looking up that native code to see what happens is not as fun as looking up java code you have seen till.
Because, though they encourage us not to use native code
, they use it because jdk
is differently released for different platforms. In most of the jdk
sources we can see some native method declarations.
Look at OpenJDK JVM sources: Thread.c and jvm.cpp (JVM_StartThread
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With