public class S03 {
private boolean isSub = true;
public synchronized void sub() throws InterruptedException {
if (!isSub) {
this.wait();
}
// do something
isSub = !isSub;
this.notify();
}
public synchronized void main() throws InterruptedException {
if (isSub) {
this.wait();
}
// do something
isSub = !isSub;
this.notify();
}
}