Download the source code library for the start0 () source method in the Thread class

I am looking for a detailed explanation. How Thread.start () internally calls the run () method. I know that its JVM, which internally calls run () using the start () method, and when I started checking the source code of the Thread class, I found these codes below:

public synchronized void start() { if(threadStatus != 0) throw new IllegalThreadStateException(); group.add(this); start0(); if(stopBeforeStart) stop0(throwableFromStop); } private native void start0(); 

Now that I see that start () calls the native start0 () method, but I don’t see any code related to loading my own code library.

Please help me understand the whole flow of calls.

Thanks Sandeep

+4
source share
2 answers

Java is open source. . A little research can also bring you the source code of the native code. You see, you yourself see the stream. See Where to find the source code for the built-in java.lang methods? .

According to: Java source code use jdk7 source

JDK 7 Thread.c: http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/00cd9dc3c2b5/src/share/native/java/lang/Thread.c

To my knowledge, finding this native code to see what happens is not as fun as finding the Java code you saw before.

Because, although they encourage us not to use native code , they use it because jdk is released differently for different platforms. In most jdk sources jdk we can see some declarations of our own methods.

+5
source

Take a look at the OpenJDK JVM sources: Thread.c and jvm.cpp ( JVM_StartThread )

0
source

Source: https://habr.com/ru/post/1485997/


All Articles