What does Runtime.getRuntime().availableProcessors() exactly return?

4.7k views Asked by At

My processor is Intel® Core™ i7-3610QM Processor (6M Cache, 2.30 GHz), which posseses 4 processor cores and 8 number of threads (what should that exactly mean?). I'm running a simple Java programm to find out the number of "processors available to the Java virtual machine." (API from Oracle, Java 7), which returns 8 for me, and not 4. Can someone explain me why is that so?

Here is the simple java code:

public class MyTest {
    public static void main(String args[]) {
        System.out.println("Number of cores available : " + Runtime.getRuntime().availableProcessors());
    }
}
1

There are 1 answers

2
ashes999 On BEST ANSWER

This is more of a hardware question IMO.

Your processor is four physical cores, plus something called "Hyper-Threading," which essentially means "tell the system you really have eight cores, even though you have four." According to Intel, this results in a 10-20% performance improvement over just expressing it as four cores.

What you're seeing is what the OS sees: eight cores. Physically, it's four cores, plus hyper-threading.

You may want to see this answer on a similar question, which states:

The number of processors is basically the number of execution engines capable of running your code. One of the i5 variants is a 4-core CPU, the i5-7 series. These may be physically distinct processors (even though they exist inside the same chip) or they may be logical processors when you're using hyper-threading.