On our Windows Server 2019, we have 36 cores and 72 logical processors, as seen in Task Manager CPU performance window. And, also, if from command prompt, if I run the command.
echo %NUMBER_OF_PROCESSORS%
It tells me 72.
However, from within Java program, if I run the following code snippet,
public class NoOfCPUs {
public static void main(String[] args) {
String envName = "NUMBER_OF_PROCESSORS";
String noOfP = System.getenv(envName);
System.out.format("%s (from env) = %s%n", envName, noOfP);
}
}
the output comes as:
NUMBER_OF_PROCESSORS (from env) = 36
Compiled with 64-bit Java 8 compiler on Windows in Netbeans IDE. Made an executable jar. Ran the jar, as:
java -jar NoOfCPUs.jar
Same system environment variable, NUMBER_OF_PROCESSORS is showing me different result from a command prompt vs from within Java program.
Why?
Is it because of logical processor group that Windows use after 2009 version? Logical processor group holds maximum of 64 processors in a group.