Automatically detecting deadlocks?

R

Rogan Dawes

Hi folks,

Being a fairly novice Java programmer, I am sure that I make many
mistakes in my coding.

One of the problems that I have encountered is deadlocks between my
application code and the Swing/AWT event thread. I am obviously trying
to synchronize() or wait() on the same object, and so the GUI stops
responding.

This is not strictly a Swing question, though, so I am posting it here
rather than c.l.j.g.

Is it possible for the JVM to print out a list of threads that are
waiting on the same semaphore/lock? I have seen references to the
HotSpot VM being able to do this, but was not able to see how to get
this to work.

I have also seen such functionality in NetBeans, running under the
debugger, where it can show you the contested lock, the threads that are
contesting it, and the stack trace for each thread showing how it got to
that point. This is exactly what I am looking for, in a slightly lighter
weight form.

Does anyone know of a debugger that would dump such information
(contested object, thread names and stack traces) when it detects this
condition? This could be helpful for both myself, and other users of my
app, in formulating bug reports or fixing the bugs themselves.

I'm kind of envisioning the following:

$ deadlockmonitor -jar myapp.jar
Deadlock detected on object ArrayList@123abc

Threads:
AWT-EventQueue-0
main

StackTraces:

AWT-EventQueue-0:
[... a stack trace ....]

main:
[... a stack trace ....]

Many thanks

Rogan
 
T

Thomas Weidenfeller

Rogan said:
Is it possible for the JVM to print out a list of threads that are
waiting on the same semaphore/lock? I have seen references to the
HotSpot VM being able to do this, but was not able to see how to get
this to work.

Reading the JVMs documentation (comes with every SDK) will enlight you
regarding the magic keystroke / signal for a thread dump:

http://java.sun.com/j2se/1.4.2/docs/tooldocs/solaris/java.html
http://java.sun.com/j2se/1.4.2/docs/tooldocs/linux/java.html
http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/java.html

Also check the JVMPI documentation with the HPROF demo profile
(documentation is also part of the SDK documentation).

/Thomas
 
R

Rogan Dawes

Thomas said:
Reading the JVMs documentation (comes with every SDK) will enlight you
regarding the magic keystroke / signal for a thread dump:

http://java.sun.com/j2se/1.4.2/docs/tooldocs/solaris/java.html
http://java.sun.com/j2se/1.4.2/docs/tooldocs/linux/java.html
http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/java.html

Also check the JVMPI documentation with the HPROF demo profile
(documentation is also part of the SDK documentation).

/Thomas

That's exactly what I was after!

Thanks a lot!

Rogan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top