start
// 同步方法
public synchronized void start() {
// 检查线程状态
if (threadStatus != 0)
throw new IllegalThreadStateException();
//添加到指定线程组,thread默认使用调用线程的线程组
group.add(this);
boolean started = false;
try {
//本地方法启动线程
start0();
started = 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 */
}
}
}
join
//所有join方法的重载最终都会进入此方法,入参为0时代表永久等待,原始语义为等待本线程死亡直到x秒
//isAlive方法由查看eetop值判断
public final synchronized void join(final long millis)
throws InterruptedException {
//有时间限制
if (millis > 0) {
if (isAlive()) {
final long startTime = System.nanoTime();
long delay = millis;
do {
//直接使用wait方法
wait(delay);
} while (isAlive() && (delay = millis -
TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime)) > 0);
}
} else if (millis == 0) {
while (isAlive()) {
wait(0);
}
} else {
throw new IllegalArgumentException("timeout value is negative");
}
}