并行:同一个CPU同时执行多个任务
并发:多个CPU时间轮换机制运行多个任务
简单监控线程代码:
public static void main(String[] args) {
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
ThreadInfo[] threadInfos = threadMXBean.dumpAllThreads(false, false);
for(ThreadInfo info : threadInfos){
System.out.println("["+info.getThreadId()+"]"+info.getThreadName());
}
}