即使在线程关闭之后,活动线程计数也不会减少

在下面的代码中,即使executor中的线程在5秒后终止,Thread.activeCount()也总是返回2。

public class MainLoop {
    public static void main(String[] args) throws Exception {
        ExecutorService executor = Executors.newFixedThreadPool(12);
        executor.submit(new Callable<Void>() {
            public Void call() throws Exception {
                Thread.sleep(5000);
                return null;
            }
        });
        while (true) {
            System.out.println(Thread.activeCount());
            Thread.sleep(1000);
        }
    }
}

我期望Thread.activeCount()在5秒后返回1。为什么总是返回2?

转载请注明出处:http://www.033230.com/article/20230331/1770195.html