标签:get stat nbsp adt 启动 thread pack ack rup
你知道java的main 方法启动后,会有多少个线程吗?
package com; import java.util.stream.Stream; /** * 你知道java的main 方法启动后,会有多少个线程吗? */ public class ThreadTest { public static void main(String[] args) throws InterruptedException { Thread mainThread = Thread.currentThread(); ThreadGroup mainThreadThreadGroup = mainThread.getThreadGroup(); //获取线程组中的线程。 int count = mainThreadThreadGroup.activeCount(); Thread[] threads = new Thread[count]; mainThreadThreadGroup.enumerate(threads, true); System.out.println(count); Stream.of(threads).forEach(thread -> System.out.println(thread.getName())); } }
输出:
2
main 主线程
Monitor Ctrl-Break 控制中断监视器
标签:get stat nbsp adt 启动 thread pack ack rup
原文地址:https://www.cnblogs.com/itbac/p/12210717.html