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

T

ThomasH

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
 
L

Larry Barowski

ThomasH said:
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.
 
T

ThomasH

Larry Barowski wrote on 29-Aug-06 15:38:
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
 
T

ThomasH

ThomasH wrote on 29-Aug-06 16:25:
Larry Barowski wrote on 29-Aug-06 15:38:

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

Babu Kalakrishnan

ThomasH said:
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.

BK
 
T

Thomas Hawtin

Babu said:
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
 
P

Piotr Kobzda

ThomasH said:
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
 
T

ThomasH

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

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top