Get no. of cores available on a system in Java

To get the no. of cores available on a system i.e. including physical cores and virtual cores.
Physical cores are the no. of cores available on your system.
Virtual cores includes the threading capability of your processor cores.
Lets say each of your core is capable of executing two threads at a time(this is called hyper-threading) then your virtual cores will be “2 x no. of cores”.

To get the no. of cores in java you use the following:

Runtime.getRuntime().availableProcessors();

This is the no. of virtual cores and as mentioned above will be “2 x no. of cores”.

Leave a Reply

Your email address will not be published. Required fields are marked *