* 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();
/**
* If this thread was constructed using a separate
* <code>Runnable</code> run object, then that
* <code>Runnable</code> object's <code>run</code> method is called;
* otherwise, this method does nothing and returns.
* <p>
* Subclasses of <code>Thread</code> should override this method.
*
* @see #start()
* @see #stop()
* @see #Thread(ThreadGroup, Runnable, String)
*/
public void run() {
if (target != null) {
target.run();
}
}
复制代码
我说一下自己的理解,希望可以帮到楼主。
首先Thread 启动一个线程 t 然后t.start()放法,先判断threadStatus != 0,因为
新的线程Status都初始化为0,表示未被使用,是一个新线程,接着加入线程池 group.add(this);
调用start0();这个方法是native的表示不是java语言实现的可能maybe是c语言实现的。
start0()描述的很清楚If this thread was constructed using a separate
* Runnable run object, then that
* Runnable object's <code>run</code> method is called;
就是说如果这个Thread是使用一个Runnable对象构造就运行Runable的run方法
否则啥也不做返回。