me0wster / javamelody

Automatically exported from code.google.com/p/javamelody
0 stars 0 forks source link

Improve Threaddump #203

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'd like to suggest to include the monitor information into the threaddump such 
that it is possible to find the reasons for deadlocks in the threaddump. If the 
threaddump is generated like this:

ThreadInfo[] infos = ManagementFactory.getThreadMXBean().dumpAllThreads(true, 
true);
for (ThreadInfo info : infos) {
   System.out.println(info);
}

(of course not to System out, but to the servlet output or whatever :-)
it will contain information about locks like the following example:

"mythread-4" Id=13 BLOCKED on java.lang.Object@32a88bc2 owned by "mythread-0" 
Id=9
    at net.stoerr.tests.ThreadDumpTest$1.run(ThreadDumpTest.java:29)
    -  blocked on java.lang.Object@32a88bc2
    at java.lang.Thread.run(Thread.java:722)

"main" Id=1 RUNNABLE
    at sun.management.ThreadImpl.dumpThreads0(Native Method)
    at sun.management.ThreadImpl.dumpAllThreads(ThreadImpl.java:446)
    at net.stoerr.tests.ThreadDumpTest.main(ThreadDumpTest.java:42)
    -  locked java.lang.Class@54182d86

Original issue reported on code.google.com by sto...@gmail.com on 22 Mar 2012 at 3:03

GoogleCodeExporter commented 9 years ago
Currently, if some threads are deadlocked, their names are already printed in 
bold and red above the list of threads in the html report.

And I have now added that line with their names at the top of the thread dumps, 
if there are threads deadlocked (revision 2678).
Thanks.

But sorry, I have not added the complete reason with the lock as you said, 
because I think that the names of the deadlocked threads and their stack-traces 
often give enough information to find the reason, and because I think that 
deadlocked threads are critical enough that some op can use "jstack" from the 
JDK if needed (and because it may be complex enough in the centralized collect 
server to be not worth it).
Note that I have never seen myself deadlocked threads in production for a real 
application, so I assume to be biased here.

I have out the status to "Fixed" and I know that it is only half-fixed.

Original comment by evernat@free.fr on 25 Mar 2012 at 5:10