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();多线程的实现需要依靠底层操作系统的支持。
start方法是使该线程开始执行;Java 虚拟机开始调用该线程的 run 方法。 run方法:如果该线程是使用独立的 Runnable 运行对象构造的,则调用该 Runnable 对象的 run 方法;否则,该方法不执行任何操作并返回。也就是说,语法规定线程run方法的内容就是要执行的操作,run只是个代号,start才是开始调用run方法的真正入口。具体详见jdk帮助文档。
/**
* 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();多线程的实现需要依靠底层操作系统的支持。
run方法:如果该线程是使用独立的 Runnable 运行对象构造的,则调用该 Runnable 对象的 run 方法;否则,该方法不执行任何操作并返回。也就是说,语法规定线程run方法的内容就是要执行的操作,run只是个代号,start才是开始调用run方法的真正入口。具体详见jdk帮助文档。