Back to index

munin  2.0.1
ThreadsDeadlocked.java
Go to the documentation of this file.
00001 package org.munin.plugin.jmx;
00002 
00003 import java.io.IOException;
00004 import java.lang.management.ManagementFactory;
00005 import java.lang.management.ThreadMXBean;
00006 
00007 import org.munin.plugin.jmx.AbstractAnnotationGraphsProvider.Graph;
00008 
00009 @Graph(title = "ThreadsDeadlocked", vlabel = "threads", info = "Returns the number of deadlocked threads for the JVM. Usually not available at readonly access level.")
00010 public class ThreadsDeadlocked extends AbstractAnnotationGraphsProvider {
00011 
00012        public ThreadsDeadlocked(Config config) {
00013               super(config);
00014        }
00015 
00016        @Field
00017        public int threadsDeadlocked() throws IOException {
00018               ThreadMXBean mxbean = ManagementFactory.newPlatformMXBeanProxy(
00019                             getConnection(), ManagementFactory.THREAD_MXBEAN_NAME,
00020                             ThreadMXBean.class);
00021 
00022               long[] deadlockedThreads = mxbean.findMonitorDeadlockedThreads();
00023               if (deadlockedThreads == null) {
00024                      return 0;
00025               } else {
00026                      return deadlockedThreads.length;
00027               }
00028        }
00029 
00030        public static void main(String args[]) {
00031               runGraph(args);
00032        }
00033 }