異常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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章