public synchronized void start() {
/**
* This method is not invoked for the main method thread or "system"
* group threads created/set up by the VM. Any new functionality added
* to this method in the future may have to also be added to the VM.
*
* A zero status value corresponds to state "NEW".
*/
if (threadStatus != 0)
throw new IllegalThreadStateException();
group.add(this);
start0();
if (stopBeforeStart) {
stop0(throwableFromStop);
}
} private native void start0();
这里的start0应该是用C语言实现的吧。
是用pthread实现的吗?
有这个的源代码吗?
/**
* This method is not invoked for the main method thread or "system"
* group threads created/set up by the VM. Any new functionality added
* to this method in the future may have to also be added to the VM.
*
* A zero status value corresponds to state "NEW".
*/
if (threadStatus != 0)
throw new IllegalThreadStateException();
group.add(this);
start0();
if (stopBeforeStart) {
stop0(throwableFromStop);
}
} private native void start0();
这里的start0应该是用C语言实现的吧。
是用pthread实现的吗?
有这个的源代码吗?
在 *nix 下可能会用 pthread,在 win32下估计就直接用 _beginthreadex。
源码估计在 JRE 的代码中。
Linux,UNIX,肯定就是pthread_create.
Windows不是_begin_thread,就是CreateThread。wait方法的实现,
往往是WaitForMultiEvents等函数实现的。
凡事jdk中的native方法,大多都是依赖操作系统来完成的,并没有什么确定性,不同操作系统不同,如果想了解底层实现,学习一下线程或者进程的知识,开发一下C语言的多线程,大概就理解了,并不需要去深究java的线程机制原理,因为那没什么用,因为java的线程机制不是固定的,是随着操作系统以及对于硬件平台来适应的。
native方法中怎么调用java的方法呢