异常java.lang.IllegalMonitorStateException

博主写代码时遇到java.lang.IllegalMonitorStateException异常,通过搜索得知JavaDoc对该异常的解释较晦涩,还提到在Object.notify()函数的JavaDoc中有关于线程成为对象监视器所有者的三种方式的相关解释。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天写代码遇到一个异常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
来源:优快云
原文:https://blog.youkuaiyun.com/historyasamirror/article/details/6709693

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值