获取java中jvm启动的线程信息

获取JVM中执行的线程信息

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;

public class MultiThread {

    public static void main(String[] args){
        //获取java的线程管理MXBean
        ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
        //不需要获取同步的monitor和synchronizer信息,仅获取线程和线程堆栈信息
        ThreadInfo[] threadInfo = threadBean.dumpAllThreads(false, false);
        //遍历线程信息,仅打印线程id和线程名称信息
        for(ThreadInfo info : threadInfo){
            System.out.println(info.getThreadId() + "--" + info.getThreadName() +"--"+ info.getThreadState().name());
        }
    }

}

你可能感兴趣的:(java,线程)