multithreadingjvmcpu-cores

Runtime.getRuntime().availableProcessors() not returning available cores


We have a highend server machine with 4 Intel Xeon E7 4850 processors (NUMA nodes) each having 10 cores with 2 threads. So effectively we have 80 core a machine. (windows task manager shows 80 cores) Now my question is when I execute Runtime.getRuntime().availableProcessors() it returns 40 and so my application spawns only 40 threads. Why is it so?


Solution

  • Unless you are using Windows 2003 which had a bug: "The number of physical hyperthreading-enabled processors or the number of physical multicore processors is incorrectly reported in Windows Server 2003"...

    ...a count of "40 Cores" is the wrong result if Hyper-Threading is enabled, which seems to be the case since Windows reports the correct number of logical CPU Cores.

    If a Java fix is not available then you can use JNI to call the GetLogicalProcessorInformation() Windows API call (source code included, works on XP SP3 and more recent).