jvm 线程

//获得JVM所有运行的线程  

 

  public static Thread[] getAllThreadForJVM() {
        ThreadGroup group = Thread.currentThread().getThreadGroup();
        ThreadGroup topGroup = group;

        // 遍历线程组树,获取根线程组
        while (group != null) {
            topGroup = group;
            group = group.getParent();
        }
        // 激活的线程数加倍
        Thread[] slackList = new Thread[topGroup.activeCount()];
        // 获取根线程组的所有线程
        int actualSize = topGroup.enumerate(slackList);
        return slackList;
    }

你可能感兴趣的:(jvm,thread)