From jdk 1.7.0_45 The instance method of Thread.join(long miilliseconds) works by making the caller Thread wait on this Thread's Object monitor.Also,the javadoc explicitly states that
As a thread terminates the this.notifyAll method is invoked. It is recommended that applications not use wait, notify, or notifyAll on Thread instances.
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;
}
wai t(delay);
now = System.currentTimeMillis() - base;
}
}
}
I don't see notifyAll() getting called so that the Thread calling join() gets the monitor for this Thread's Object
If I am calling t.join(0)
on thread t,then I am not implementing notifyAll()
in my run() code.So how does the caller thread(the thread which calls t.join() gets notified)