23

I am trying to check the performance of a program. I refer this post get OS-level system information. When Runtime.availableProcessors() executes, I get an answer of 4. I read availableProcessors() but it tells that this method returns number of processors

  1. Can anyone explain what is mean by number of processors ?
  2. Why am getting 4 as result ?

I am using Windows 7 core i5 4gp.

Nathan
  • 8,093
  • 8
  • 50
  • 76
Amith
  • 1,907
  • 5
  • 29
  • 48
  • do you have quad core processor machine ? – Ved Aug 09 '12 at 06:38
  • 1
    or a dualcore with hyper-threading ? – Dahaka Aug 09 '12 at 06:40
  • 2
    Not all i3, i5 or i7 are the same. An i3 can have one or two cores with or without hyper threading. An i7 can have 4 or 6 cores. It might be useful to look up your exact model on the intel website. Here is an example. http://ark.intel.com/products/52210/Intel-Core-i5-2500K-Processor-%286M-Cache-3_30-GHz%29 Note how many options there are! – Peter Lawrey Aug 09 '12 at 07:08

5 Answers5

36

As you've read, availableProcessors() is a method that returns the number of processors available to the JVM. 4 means the number of processors currently available for JVM.

These lines return the number of logical cores on Windows and in other operating systems.

On a computer with a quad-core Core i7 supporting Hyper-Threading, it will return 8.

On a computer with a quad-core Q6700, this method will return 4.

talha2k
  • 24,937
  • 4
  • 62
  • 81
  • This returns the number of physical cores, not logical ones. `Aug 02, 2023 11:51:48 AM java.util.prefs.FileSystemPreferences$1 run INFO: Created user preferences directory. | Welcome to JShell -- Version 11.0.19 | For an introduction type: /help intro jshell> System.out.println(Runtime.getRuntime().availableProcessors()) 8` However this machine had 16 logical cores. only 8 physical cores – Satyam Raj Aug 02 '23 at 11:52
22

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.

See http://en.wikipedia.org/wiki/Intel_Core#Core_i5 and http://en.wikipedia.org/wiki/Hyper-threading for more detail.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
3

You have a multi-core processor (in your case, it looks like it's Lynnfield). Each core counts as a separate CPU (a separate processor) for the purpose of the information, since each core can execute instructions at the same time as the others.

mikołak
  • 9,605
  • 1
  • 48
  • 70
3

It gives no of cores that are available to jvm process. it may larger that actual if hyper threading is enable.

Nirmal- thInk beYond
  • 11,847
  • 8
  • 35
  • 46
0

In this context, a "processor" is "hardware capable of independent execution", ie a cpu core.

It is not the "processor package" - the single hardware unit you buy (that is actually 4 independent CPUs in one package)

Bohemian
  • 412,405
  • 93
  • 575
  • 722