publicfinalvoidjoin()throws InterruptedException { join(0); } //同步方法,wait操作需要获取锁 publicfinalsynchronizedvoidjoin(long millis)throws InterruptedException { long base = System.currentTimeMillis(); long now = 0;
//... if (millis == 0) { while (isAlive()) { wait(0); //即this.wait()调用线程持有锁进入,一直等待在this线程实例上并放锁,直到被唤醒 } } else { while (isAlive()) { long delay = millis - now; if (delay <= 0) { break; } wait(delay); now = System.currentTimeMillis() - base; } } }