2

I understand that we can easily make use of all available CPU cores using parallel streams or threads in Java.

However, let's say my desktop has two physical CPUs (yes, I mean CPUs not cores), will the JVM make use of them both (considering they are available of course), just like it does with the CPU Cores?

Thanks!

nevets1219
  • 7,692
  • 4
  • 32
  • 47
FelipeKunzler
  • 1,204
  • 1
  • 11
  • 17
  • Please read my question again, I'm talking about Multi-CPUs and NOT Multi-cores. – FelipeKunzler Feb 23 '17 at 00:23
  • Which JVM are you talking about? – weston Feb 23 '17 at 00:23
  • Not any specifically, is this possible depending on the JVM? – FelipeKunzler Feb 23 '17 at 00:25
  • Lots of answers if you look for them: http://stackoverflow.com/questions/1223072/forcing-multiple-threads-to-use-multiple-cpus-when-they-are-available – Morrison Chang Feb 23 '17 at 00:27
  • @MorrisonChang They all assume cores and CPUs are identical to the JVM. Though I don't see why one would think otherwise. – shmosel Feb 23 '17 at 00:30
  • Every core is a logical CPU and viewed as a processor to the OS so I can't see why a jvm would differ. – ChiefTwoPencils Feb 23 '17 at 00:38
  • Why the big deal to distinguish "CPU" from "core"? They're equivalent. – Lew Bloch Feb 23 '17 at 00:41
  • 1
    Some interesting read: https://dzone.com/articles/building-multi-core-ready-java - I don't think it's fair to assume that multiple physical CPU is the same as one physical CPU with multiple cores, at least without providing some information to back that claim – nevets1219 Feb 23 '17 at 00:43
  • I didn't know multiple CPUs and cores were seen as equal in the eyes of the OS/JVM. Thought they were handled differently somehow. Thanks! – FelipeKunzler Feb 23 '17 at 00:44
  • 2
    @nevets1219, read [this](https://www.amazon.com/Operating-System-Concepts-Abraham-Silberschatz/dp/0470128720); specifically section1.3.2. "multicore systems are multiprocessor systems but not all multiprocessor are multicore".. – ChiefTwoPencils Feb 23 '17 at 01:01
  • 1
    @ChiefTwoPencils unfortunately, Amazon didn't allow me to preview page 13 (section 1.3.2) but I'll take your word on it. I think addressing it from an OS point of view is a good start. Your claim is backed up on [Wikipedia](https://en.wikipedia.org/wiki/Symmetric_multiprocessing): "Most multiprocessor systems today use an SMP architecture. In the case of multi-core processors, the SMP architecture applies to the cores, treating them as separate processors." - Another good read is https://en.wikipedia.org/wiki/Multiprocessing – nevets1219 Feb 23 '17 at 01:10

1 Answers1

4

The JVM is a just a specification that:

...omits implementation details that are not essential to ensure interoperability: the memory layout of run-time data areas, the garbage-collection algorithm used, and any internal optimization of the Java virtual machine instructions (their translation into machine code)

It would be another implementation detail how it uses physical hardware. I could write my own JVM implementation that uses just one CPU just fine or I can write one that uses more than one.

Pedantry aside, I would imagine that all commercial JVMs see multiple CPUs in exactly the same way as multiple cores because they generally run on top of Operating Systems which also abstract away hardware details about CPUs, and cores (including virtual cores) and present them all as CPUs to software running on top of that OS.

weston
  • 54,145
  • 21
  • 145
  • 203