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 发布
本文探讨了并发编程中线程安全问题的核心概念,通过分析一个简单的Java并发实例,展示了如何正确理解和处理线程同步问题,以确保程序在多线程环境下运行的稳定性和可靠性。
2067

被折叠的 条评论
为什么被折叠?



