11

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

6 Answers 6

11

If you are using a Sun JVM then attach with JConsole and go to the Threads pane. There is a "Detect Deadlock" button.

Sign up to request clarification or add additional context in comments.

Comments

4

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).

Comments

1

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.

Comments

1

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.

Comments

0

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.

1 Comment

YourKit has the best representation of threads and sometimes it can even detect the deadlock automatically.
-1

I would recommend using a static analysis tool like

FindBugs

, which can often detect Deadlocks at compile-time

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.