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();
}
}
多线程 : 使用 wait 和 notify 实现进程间同步通信
最新推荐文章于 2020-02-13 08:51:47 发布