为什么在Java中object.wait()/notify()方法必须在持有锁的情况下才能执行?java.lang.IllegalMonitorStateException报错分析
先贴代码class Procum { private volatile int product = 0; public synchronized void product() throws InterruptedException { while (product != 0) { wait(); } product++; System.out.println("生产了第" + product + "
原创
2021-06-18 11:59:37 ·
886 阅读 ·
1 评论