/*** Causes this thread to begin execution; the Java Virtual Machine
* calls the run
method of this thread.
让这个线程开始执行。JVM会调用这个线程的run()方法。
*
* The result is that two threads are running concurrently: the
* current thread (which returns from the call to the
* start
method) and the other thread (which executes its
* run
method).
*
* It is never legal to start a thread more than once.一个线程多次调用start()方法是非法的。
* In particular, a thread may not be restarted once it has completed
* execution.
*特别说明:一个线程执行完后,不太可能重新运行。
*@exceptionIllegalThreadStateException if the thread was already
* started.
如果该线程已经启动,则再次调用start()方法,就会抛出IllegalThreadStateException异常。
*@see#run()
*@see#stop()*/
public synchronized voidstart() {/*** 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)//新的线程threadState值是0
throw newIllegalThreadStateException();/*Notify the group that this thread is about to be started
* so that it can be added to the group's list of threads
* and the group's unstarted count can be decremented.*/group.add(this);//通知线程组该线程将要开始运行,这样该线程就会被添加到线程列表中,此时列表的unstarted数将会减少。
boolean started = false;try{
start0();//调用原生方法态方法启动线程
started = true;//已经运行的标记设置为true
} finally{try{if (!started) {//若开始运行标记未设置成功,则通知线程组该线程尝试运行失败
group.threadStartFailed(this);
}
}catch(Throwable ignore) {/*do nothing. If start0 threw a Throwable then
it will be passed up the call stack*/}
}
}