Can we display list of held monitors and their holders in JVM?

Discussion in 'Java' started by ThomasH, Aug 29, 2006.

  1. ThomasH

    ThomasH Guest

    I wonder if there is a possibility to access the list of
    locks/monitors and display them in Java, kind of similar
    to what we do with threads and thread lists. This would
    greatly simplify search for contentions and maybe even
    for deadlocks.

    ThomasH, Aug 29, 2006
    1. Advertisements

  2. Most debuggers do this. I don't think there is a way
    to do it from within a Java program though.
    Larry Barowski, Aug 29, 2006
    1. Advertisements

  3. ThomasH

    ThomasH Guest

    Larry Barowski wrote on 29-Aug-06 15:38:
    This occurred to me too, I wanted verify if I miss something.

    The reason for this omission is not obvious to me,
    finally we have a full knowledge of all granted Java
    lacks and of all pending classes and threads in the JVM.

    ThomasH, Aug 30, 2006
  4. ThomasH

    ThomasH Guest

    ThomasH wrote on 29-Aug-06 16:25:
    Actually, on Unix and Linux, if you run jdk 1.4 or later
    with hotspot and issue "kill -3" against the Java process,
    JVM will dump threads. Its not precisely what I need, but
    it contains the information looked after...
    ThomasH, Aug 30, 2006
  5. I believe a Ctrl-Break on the console does the same on Windows as well.

    Babu Kalakrishnan, Aug 30, 2006
  6. Or ctrl-\ on Solaris or Linux. I believe from 1.5 jstack (and presumably
    jconsole) will do it without requiring access to the process output.

    From 1.6 a program can examine its own locks (without connecting to its
    own debugging port) through As an example, I wrote
    some code to detect when java.awt.EventQueue.invokeAndWait is called
    with a lock held:

    IIRC in 1.5 you will only get details of intrinsic locks. From 1.6 you
    will also get details from java.utiil.concurrency.locks.

    Tom Hawtin
    Thomas Hawtin, Aug 30, 2006
  7. ThomasH

    Piotr Kobzda Guest

    Take a look at a ThreadInfo and ThreadMXBean classes from package.
    Note this API is extended in Mustang with additional support for
    java.util.concurrent locks.

    Piotr Kobzda, Aug 30, 2006
  8. ThomasH

    ThomasH Guest

    Thomas Hawtin wrote on 30-Aug-06 05:36:
    Very nice idea, thanks!
    ThomasH, Aug 30, 2006
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.