Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
ThomasH - 29 Aug 2006 19:21 GMT
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
Larry Barowski - 29 Aug 2006 23:38 GMT
>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.
ThomasH - 30 Aug 2006 00:25 GMT
Larry Barowski wrote on 29-Aug-06 15:38:
>> I wonder if there is a possibility to access the list of
>> locks/monitors and display them in Java, kind of similar
[quoted text clipped - 4 lines]
> 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 - 30 Aug 2006 03:09 GMT
ThomasH wrote on 29-Aug-06 16:25:
> Larry Barowski wrote on 29-Aug-06 15:38:
>>> I wonder if there is a possibility to access the list of
[quoted text clipped - 5 lines]
>> 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.
[quoted text clipped - 4 lines]
>
> Thomas
Babu Kalakrishnan - 30 Aug 2006 04:25 GMT
> ThomasH wrote on 29-Aug-06 16:25:
> > Larry Barowski wrote on 29-Aug-06 15:38:
[quoted text clipped - 11 lines]
> 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
Thomas Hawtin - 30 Aug 2006 13:35 GMT
>> ThomasH wrote on 29-Aug-06 16:25:
>>> Larry Barowski wrote on 29-Aug-06 15:38:
[quoted text clipped - 11 lines]
>
> 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
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

ThomasH - 30 Aug 2006 21:42 GMT
Thomas Hawtin wrote on 30-Aug-06 05:36:
>>> 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,
[quoted text clipped - 12 lines]
>
> 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
Piotr Kobzda - 30 Aug 2006 13:51 GMT
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.