0

For example, I have 4 core processor with 8 threads. I pretty sure, that this amount of threads does not directly relate on amount of java's threads.

  • 1
    Checkout this [link](https://stackoverflow.com/questions/34689709/java-threads-and-number-of-cores) which has extensively answered your question. – aLuViAn Jan 26 '20 at 09:03
  • unfortunately, hardware and software engineers use terms "thread" and "processor" in different ways. Processor threads are processors from software point of view. – Alexei Kaigorodov Jan 26 '20 at 09:18

1 Answers1

6

As per my understanding you are talking about 4 actual cores and 2 Hyper-thread per core which means technically 8 virtual core (vCpu). Which means 8 threads can execute parallel without any context switch (Lets do not consider the complications of Hyper-threads here)

Java threads are one to one mapped with the OS threads which is NOT one to one mapped with hardware threads. Which means for thread allocation and context switch, Java depends on the underlying OS on which JVM is running. OS can create as many threads it wants, which can run on any of the available vCPUs on the processor. As OS threads keep on increasing, there will be more context switches and performance may get affected if threads are NOT doing IO bound work.

Saurav Kumar Singh
  • 1,352
  • 7
  • 18