异常java.lang.IllegalMonitorStateException

今天写代码遇到一个异常java.lang.IllegalMonitorStateException,百度问题,搜索blog得知

JavaDoc上关于IllegalMonitorStateException的解释是:
Thrown to indicate that a thread has attempted to wait on an object’s monitor or to notify other threads waiting on an object’s monitor without owning the specified monitor.
看起来有些晦涩难懂,比如object’s monitor。其实,在Object.notify()这个函数的JavaDoc中有相关的解释:
A thread becomes the owner of the object’s monitor in one of three ways:
1). By executing a synchronized instance method of that object.
2). By executing the body of a synchronized statement that synchronizes on the object.
3). For objects of type Class, by executing a synchronized static method of that class. ---------------------
作者:historyasamirror
来源:CSDN
原文:https://blog.csdn.net/historyasamirror/article/details/6709693

你可能感兴趣的:(java编程)