JAVA查看线程信息

在JDK1.5中,java.lang.Thread类新增了一个getAllStackTraces()方法用于获取虚拟机中所有线程的StackTraceElement对象。

        for(Map.Entry<Thread, StackTraceElement[]> stackTrace : Thread.getAllStackTraces().entrySet()){
            Thread thread = (Thread)stackTrace.getKey();
            StackTraceElement[] stack = (StackTraceElement[])stackTrace.getValue();
            if(thread.equals(Thread.currentThread())){
                continue;
            }
            System.out.print("
线程:"+thread.getName()+"
");
            for(StackTraceElement element: stack){
                System.out.print("	"+element+"
");
            }
        }
原文地址:https://www.cnblogs.com/yasong-zhang/p/4626284.html