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.

    Thomas
    ThomasH, Aug 29, 2006
    #1
    1. Advertising

  2. "ThomasH" <> wrote in message
    news:3U%Ig.64$...
    >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.


    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
    #2
    1. Advertising

  3. ThomasH

    ThomasH Guest

    Larry Barowski wrote on 29-Aug-06 15:38:
    > "ThomasH" <> wrote in message
    > news:3U%Ig.64$...
    >> 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.

    >
    > Most debuggers do this. I don't think there is a way
    > to do it from within a Java program though.
    >


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

    Thomas
    ThomasH, Aug 30, 2006
    #3
  4. ThomasH

    ThomasH Guest

    ThomasH wrote on 29-Aug-06 16:25:
    > Larry Barowski wrote on 29-Aug-06 15:38:
    >> "ThomasH" <> wrote in message
    >> news:3U%Ig.64$...
    >>> 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.

    >>
    >> Most debuggers do this. I don't think there is a way
    >> to do it from within a Java program though.


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

    >>

    >
    > Thanks.
    > 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.
    >
    > Thomas
    ThomasH, Aug 30, 2006
    #4
  5. ThomasH wrote:
    > ThomasH wrote on 29-Aug-06 16:25:
    > > Larry Barowski wrote on 29-Aug-06 15:38:
    > >> "ThomasH" <> wrote in message
    > >> news:3U%Ig.64$...
    > >>> 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.
    > >>
    > >> Most debuggers do this. I don't think there is a way
    > >> to do it from within a Java program though.

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


    I believe a Ctrl-Break on the console does the same on Windows as well.

    BK
    Babu Kalakrishnan, Aug 30, 2006
    #5
  6. Babu Kalakrishnan wrote:
    > ThomasH wrote:
    >> ThomasH wrote on 29-Aug-06 16:25:
    >>> Larry Barowski wrote on 29-Aug-06 15:38:
    >>>> "ThomasH" <> wrote in message
    >>>> news:3U%Ig.64$...
    >>>>> 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.
    >>>> Most debuggers do this. I don't think there is a way
    >>>> to do it from within a Java program though.

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

    >
    > I believe a Ctrl-Break on the console does the same on Windows as well.


    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 java.lang.management. As an example, I wrote
    some code to detect when java.awt.EventQueue.invokeAndWait is called
    with a lock held:

    http://jroller.com/page/tackline?entry=detecting_invokeandwait_abuse

    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
    --
    Unemployed English Java programmer
    http://jroller.com/page/tackline/
    Thomas Hawtin, Aug 30, 2006
    #6
  7. ThomasH

    Piotr Kobzda Guest

    ThomasH wrote:

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


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


    piotr
    Piotr Kobzda, Aug 30, 2006
    #7
  8. ThomasH

    ThomasH Guest

    Thomas Hawtin wrote on 30-Aug-06 05:36:
    > Babu Kalakrishnan wrote:
    >>> 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...
    >>>

    >>
    >> I believe a Ctrl-Break on the console does the same on Windows as well.

    >
    > 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 java.lang.management. As an example, I wrote
    > some code to detect when java.awt.EventQueue.invokeAndWait is called
    > with a lock held:
    >
    > http://jroller.com/page/tackline?entry=detecting_invokeandwait_abuse


    Very nice idea, thanks!

    >
    > 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
    ThomasH, Aug 30, 2006
    #8
    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. Guest

    Place holders

    Guest, Nov 13, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    422
    Chris Jackson
    Nov 13, 2003
  2. Soefara
    Replies:
    4
    Views:
    704
    John C. Bollinger
    Nov 18, 2003
  3. Replies:
    0
    Views:
    288
  4. Scott L / Ram S
    Replies:
    0
    Views:
    351
    Scott L / Ram S
    Aug 10, 2006
  5. katmagic
    Replies:
    2
    Views:
    272
    Hillbilly
    Nov 17, 2008
Loading...

Share This Page