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实现的吗?
有这个的源代码吗?

解决方案 »

  1.   

    声明了 native, 就是用 C/C++ 实现的。
    在 *nix 下可能会用 pthread,在 win32下估计就直接用 _beginthreadex。
    源码估计在 JRE 的代码中。
      

  2.   

    java包的src里面好像没有native方法的源代码,就搞不清楚怎么实现了。
      

  3.   

    很简单,start0,
    Linux,UNIX,肯定就是pthread_create.
    Windows不是_begin_thread,就是CreateThread。wait方法的实现,
    往往是WaitForMultiEvents等函数实现的。
      

  4.   

    下载jdk源代码包有jdk 中native方法的实现源码,大部分是C语言的,有少量是C++语言的。jdk源代码在sun官方可以下载到,大概100多M的样子。
    凡事jdk中的native方法,大多都是依赖操作系统来完成的,并没有什么确定性,不同操作系统不同,如果想了解底层实现,学习一下线程或者进程的知识,开发一下C语言的多线程,大概就理解了,并不需要去深究java的线程机制原理,因为那没什么用,因为java的线程机制不是固定的,是随着操作系统以及对于硬件平台来适应的。
      

  5.   

    在start里要调用run函数,start里只有start0方法可能调用run函数
    native方法中怎么调用java的方法呢