Why am I getting IllegalMonitorStateException?

后端 未结 2 461
借酒劲吻你
借酒劲吻你 2021-01-19 01:14

I get the following Exception being thrown when I try to unlock an object.

Exception in thread \"Thread-1\" java.lang.IllegalMonitorStateException
    at jav         


        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-19 01:45

    The documentation is pretty clear:

    If the current thread is the holder of this lock then the hold count is decremented. If the hold count is now zero then the lock is released. If the current thread is not the holder of this lock then IllegalMonitorStateException is thrown.

    So the thread which is trying to unlock isn't the holder of the lock. We can't tell why you expected it to be the same thread without seeing more of your code.

提交回复
热议问题