Automatically detecting deadlocks?

Discussion in 'Java' started by Rogan Dawes, May 5, 2004.

  1. Rogan Dawes

    Rogan Dawes Guest

    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
    --
    Rogan Dawes

    *ALL* messages to will be dropped, and added
    to my blacklist. Please respond to "nntp AT dawes DOT za DOT net"
    Rogan Dawes, May 5, 2004
    #1
    1. Advertising

  2. Rogan Dawes wrote:
    > 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
    Thomas Weidenfeller, May 5, 2004
    #2
    1. Advertising

  3. Rogan Dawes

    Rogan Dawes Guest

    Thomas Weidenfeller wrote:

    > Rogan Dawes wrote:
    >
    >> 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


    That's exactly what I was after!

    Thanks a lot!

    Rogan
    --
    Rogan Dawes

    *ALL* messages to will be dropped, and added
    to my blacklist. Please respond to "nntp AT dawes DOT za DOT net"
    Rogan Dawes, May 6, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Martin Blackstone [MVP - Exchange]

    ASP.NET Deadlocks

    Martin Blackstone [MVP - Exchange], Aug 23, 2003, in forum: ASP .Net
    Replies:
    6
    Views:
    750
    Nick Wienholt
    Aug 24, 2003
  2. Mike Carr

    Deadlocks

    Mike Carr, Jul 16, 2004, in forum: ASP .Net
    Replies:
    9
    Views:
    625
    Mike Carr
    Jul 23, 2004
  3. deadlocks

    , Dec 8, 2005, in forum: Java
    Replies:
    31
    Views:
    1,476
    Steve Horsley
    Dec 22, 2005
  4. commie
    Replies:
    16
    Views:
    1,031
  5. Eloff
    Replies:
    14
    Views:
    484
    Tim Peters
    Jun 23, 2005
Loading...

Share This Page