java本身是一个多线程
package com.mjtabu.api.thread;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
/**
* @ClassName OnlyMain
* @Description TODO 测试java天生就是多线程
* @Author 踏步
* @Date 2020/4/13 20:54
**/
public class OnlyMain {
public static void main(String[] args) {
//java虚拟机线程管理的接口
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
//不需要获取同步的monitor和synchronizer信息,仅仅获取线程和线程堆栈信息
ThreadInfo[] threadInfos = threadMXBean.dumpAllThreads(false,false);
for(ThreadInfo threadInfo : threadInfos){
System.out.println("["+threadInfo.getThreadId()+"]"+threadInfo.getThreadName());
}
}
}
运行结果: