In the below code, Thread.activeCount() returns 2 always even though the thread in executor terminates after 5 seconds.
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);
}
}
}
I expected Thread.activeCount() to return 1 after 5 seconds. Why is it always returning 2 ?