I encountered an interesting issue today.
I work with some code that relies heavily on the database it backs on to. Today, it was backed onto Microsoft SQL Server. Right after starting, it would deadlock.
Looking at the stack of randomly picked threads I found that one was waiting indefinitly for the server to return.
A quick glance at the SQL Server's Activity Monitor revealed that "process id" 3, was waiting for "process id" 1. "Process id" 1 was sleeping, but in a transaction.
That's helpful, I thought, I now know the problem, "process id" 1. So, where's it happening in code? Uh oh.
I poked around, and noticed that
com.microsoft.sqlserver.jdbc.SQLServerConnection (no, not
com.microsoft.jdbc.sqlserver.SQLServerConnection) has a piece of private implementation called
transactionDescriptor, an 8-
byte array including the process id on the SQL Server. I set a detail formatter to show just this value.
Following this, Eclipse's find all instances command comes into play, allowing you to search for all instances of
SQLServerConnection, then all references to the specified connection. Both of these are only available in Java 6 and above, otherwise the command will be greyed out.
From here, you can (manually, as far as I know) search through the stack trace and hopefully find that one of your threads has the above class (or a class that refers to the class, or a class that refers to a class that...) in it's trace; the culprit.
A mere hour of my day, gone. :|