Reputation:
What techniques can one use to debug what appears to be a deadlock in a Java program.
My IDE is Eclipse and I think I've identifid the two deadlocked threads. In the debugger, right-clicking any of the threads in question and selecting suspend suspends the thread and displays the code currently being executed. Attempting step-into or step-over the line question appears to have no effect - the thread state changes to "Stepping" with control never returning to the debugger unless suspend is clicked again.
Thanks
Upvotes: 11
Views: 15527
Reputation: 41
A few minutes ago I stumbled upon this:
http://runnerwhocodes.blogspot.com/2007/10/deadlock-detection-with-eclipse.html
For me it looks like the best approach detect deadlocks (even it would not help in each case, e.g. detecting deadlocks in combination with EMT-Locks).
Upvotes: 4
Reputation: 62254
I would recommend using a static analysis tool like
, which can often detect Deadlocks at compile-time
Upvotes: -1
Reputation: 75426
If you are using a Sun JVM then attach with JConsole and go to the Threads pane. There is a "Detect Deadlock" button.
Upvotes: 11
Reputation: 16375
I don't know about eclipse but what you are looking for is a profiler. Checkout JProfiler or have a look at this list for example. The profiler connects directly to the JVM and visualizes what's going on inside your program in real time. When deadlocks occur you get visual/textual clues of which threads are in conflict.
Upvotes: 0
Reputation: 7832
The debugging window that shows the stacks of the various threads will indicate when a thread stops. When two threads are stopped, you can examine what each is waiting on. Finding something in common will tell you the source of the deadlock.
Upvotes: 1
Reputation: 16375
When running the program in "console mode", you can hit ctrl+break
, which gives you a thread dump. Once you run into the deadlock, this could be helpful. If the deadlock doesn't appear all too often, it could be difficult to catch the deadlock like this however.
Upvotes: 1