The following java code tells us how many processors your PC have.
int cores = Runtime.getRuntime().availableProcessors();
However, if your JVM is running in a virtue machine image, e.g. amazon EC2, VMWare, the cores reported is virtue Processor simulated by the virtue machine. Sometimes 8 core virtue CPU could be slower than 2 core physical CPU, because those 8 core can be supported by a single core physical CPU; Sometimes 8 core hardware CPU could be slower than 2 core virtue CPU, because one virtue core can be supported by multiple physical cores.Since number of virtue cores are irrelevant to the number of physical cores, optimize your thread numbers based on this information sometimes is very wrong.