public class ShareResource {
private int n = 0;
public synchronized void p() throws InterruptedException {
while (n > 0) {
wait();
}
n++;
}
public synchronized void r() {
n = 0;
notifyAll();
}
}
If I started two threads with this resource and they are both at wait() and I called the method r() in the resource would this wake both threads without checking the condition? Would the code be read until the end of the method in both threads?At the "same" time?