How Java multi-threaded program is able to use multiple CPU cores?

后端 未结 4 1466
失恋的感觉
失恋的感觉 2020-12-24 03:18

Could someone please provide explanation how Java multi-threaded program (e.g. Tomcat servlet container) is able to use all cores of CPU when JVM is only single process on l

相关标签:
4条回答
  • 2020-12-24 03:43

    The JVM is a single process with many threads. Each thread can be scheduled on a different CPU core. A single process can have many threads.

    When Java software running inside the JVM asks for another thread the JVM starts another thread.

    That is how the JVM manages to use multiple cores.

    0 讨论(0)
  • 2020-12-24 03:49

    I would start by reading the Concurrency Tutorial.

    In particular, it explains the differences (and relationship) between processes and threads.

    On the architectures that I'm familiar with, the threads (including JVM-created threads) are managed by the OS. The JVM simply uses the threading facilities provided by the operating system.

    0 讨论(0)
  • 2020-12-24 03:56

    The Linux kernel supports threads as first-class citizens. In fact to the kernel a thread isn't much different to a process, except that it shares a address space with another thread/process.

    Some old versions of ps even showed a separate process for each thread by default and newer versions can enable this behavior using the -m flag.

    0 讨论(0)
  • 2020-12-24 03:59

    If you use the concurrency library and split up your work as much as you can, the JVM should handle the rest.

    Take a look at this http://embarcaderos.net/2011/01/23/parallel-processing-and-multi-core-utilization-with-java/

    0 讨论(0)
提交回复
热议问题