Java启动时默认创建了多少线程

    Java启动时默认创建了多少线程,其实在Java本身启动时会创建若干个线程,除了main线程之外,还有Monitor Ctrl-Break,Signal Dispatcher,Finalizer,Reference Handler。

    

package org.sun.sample.pojo;

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

/**
 * 线程信息
 */
public class ThreadInfoSample {

    private ThreadInfo threadInfo;

    public ThreadInfoSample() {
        ThreadMXBean bean = ManagementFactory.getThreadMXBean();
        long[] ids = bean.getAllThreadIds();
        ThreadInfo[] infos = bean.getThreadInfo(ids);
        for (ThreadInfo info : infos) {
            System.out.println(info.getThreadName());
        }

    }

}

打印出来的信息如下:

Monitor Ctrl-Break
Signal Dispatcher
Finalizer
Reference Handler
main

Process finished with exit code 0



你可能感兴趣的:(java,线程,自动创建)