join的方法是使主线程阻塞,可是从源码看哪里看出是主线程阻塞而不是子线程呢?
wait()哪里说命了是主线程。还有isAlive哪里说明了是判断主线程的存活状态。
public static void main(String[] agrs){
Thread a = new Thread();
a.join();
System.out.pring("最后执行");
}
public final synchronized void join(long millis)
throws InterruptedException {
long base = System.currentTimeMillis();
long now = 0;
if (millis < 0) {
throw new IllegalArgumentException("timeout value is negative");
}
if (millis == 0) {
while (isAlive()) {
wait(0);
}
} else {
while (isAlive()) {
long delay = millis - now;
if (delay <= 0) {
break;
}
wait(delay);
now = System.currentTimeMillis() - base;
}
}
}