Java threads waiting to lock object that isn't (visibly) locked

怎甘沉沦 提交于 2019-12-05 07:51:40

It is possible (although unlikely) that a thread just released the monitor when your thread dump was taken. There can be a brief period between when a monitor is released and the next thread gets it. If you're not in an actual deadlock, this could explain what you are seeing. Try another thread dump and check that one.

More likely, there is a thread in there somewhere that already holds the monitor. Sometimes it isn't obvious. Your stack traces have some "locked" lines which list threads which hold certain locks, but that list isn't necessarily complete. For instance, I suspect locks obtained via JNI aren't listed.

If you could replace the built-in lock with, e.g. java.util.concurrent.locks.ReentrantLock, then you could suspend the program and attach a debugger, find the lock you care about, and find the lock owner using the getOwner method.

If you're using Eclipse, you can use the built-in lock viewer via the Debug view which might be helpful. You can enable it using the drop down menu accessible via the downward arrow in the toolbar :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!