find out a snip of multi-thread testing code. when try to run it on NetBeans, encounter an error
IllegalMonitorStateException: current thread not owner
After investigation, find out the root cause is:
can't do a notifyAll without having a lock on the object first.
So record it as a knowledge capture.
code as following:
Main.java
Forum.java
Member.java
本文探讨了多线程环境下进行单元测试时遇到的IllegalMonitorStateException异常问题,并深入分析其根本原因在于未先获取对象锁便调用notifyAll()方法。通过具体的Java代码示例,展示了如何在多线程场景下正确使用synchronized关键字及wait和notify机制。
292

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



