Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Normally when I ask for a thread dump, the symptoms of a poorly performing system are easily explained; i.e. normally I would be able to see that a number of threads are clearly waiting on a monitor which has been acquired but not released by another.

In this case, I have a lot of threads waiting for a monitor (0x965ad100), but none appears to have that monitor in the first place. The threads in question can be identified with this signature:

waiting to lock <0x965ad100> (a uk.gov.dti.og.fox.ConAgent)

I've tried Googling this, and all I seem to find are posts that discuss monitors that are locked, nothing about waiting for a monitor that isn't locked.

Thread dump in full: http://www.basson.at/docs/stackoverflow/thread_dump.txt

I hope someone here can explain what I'm seeing, or at least point me in the right direction. Thanks in advance for any responses.

like image 807
Ben Avatar asked Nov 13 '10 20:11

Ben


1 Answers

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.

like image 156
Keith Randall Avatar answered Nov 14 '22 23:11

Keith Randall