Java检测死锁之ThreadMXBean

public static void main(String[] args) {
        ThreadMXBean mbean = ManagementFactory.getThreadMXBean();
        // 只能检测 synachrozied 同步代码块 的死锁
        // long[] deadlockedThreadIds = mbean.findMonitorDeadlockedThreads();

        // 可以检测 juc下的 Lock造成的死锁和 synachrozied代码块的死锁
        long[] deadlockedThreadIds = mbean.findDeadlockedThreads();

        if (deadlockedThreadIds != null) {
            ThreadInfo[] threadInfos = mbean.getThreadInfo(deadlockedThreadIds);

            for (ThreadInfo ti : threadInfos) {
                System.out.println(ti);
            }
        }
    }

 

    原文作者:liron
    原文地址: http://www.cnblogs.com/ironroot/p/8582980.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞