The following trivial Java code:
public class Main {
public static void main(String[] args) throws InterruptedException {
System.out.println("Start");
Thread.sleep(5000);
System.out.println("Done");
}
}
Runs using 14 threads. I know that theres some GC thread running in the background, but what are the others for? Why are there so many threads? I’m on Gentoo Linux with Java 1.6.0_26. Compiling with Eclipse’s compiler or javac doesn’t make a difference(Running it in Eclipse in debug mode adds 3 more threads to it, but that’s probably justified).
My JVM (1.6.0_26) spawns even more threads by default. Most have pretty descriptive names that hint at their purpose:
Clearly, most of the threads have to do with memory handling: there are 8 garbage collector threads, plus the low memory detector.
FinalizerandReference Handlersound like they are also involved in memory management.C2 CompilerThread0/1almost certainly have to do with just-in-time compilation.VM Periodic Task Threadis explained here: What is the "VM Periodic Task Thread"?As to the exact purpose of the remaining threads, I am not sure.