据我所知,对象调用wait(),则访问对象的线程wait,那么如果是线程对象调用wait()方法,谁wait呢?
哪位同学以前思考过吗?
谢谢!
// 使用案例: 线程的Join方法中
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;
}
}
}
```