I am just trying to avoid context switching as it introduces a lot of latency. So If I am thinking that correctly, I want to have at maximum one thread per processor. If the processor supports virtual parallelism (hyper-threading I think it is the name!) then I can have the double number of threads.
Ex: 4 processors with hyperthreading = 8 threads max.
Of course the OS needs the processor as well, so I am maybe being naive here.
Anyways, knowing the number of threads the JVM creates on startup is a good start.
The JVM only starts 1 user thread, also called the “Main” thread. There are other threads that are running behind the scenes such as garbage collectors, compilers, optimizers, finalizers, etc..
A quick look at a thread dump for a nothing little app:
Shows: