Single thread program to make use of multiple cores

前端 未结 3 1295
南旧
南旧 2021-01-17 20:36

Can a single thread of a Java program automatically make use of multiple cores on the CPU?

相关标签:
3条回答
  • 2021-01-17 21:15

    Can a single thread of a Java program automatically make use of multiple cores on the CPU?

    Yes and no. A single threaded Java program will use multiple threads in that the GC, JMX, finalizer, and other background threads can run in different CPUs (whether CPU or core). The GC threads especially give a significant performance boost if they can be running in another CPU. However, your single threaded application code, although it may move between CPUs, will never be running in 2 CPUs at the same time.

    how to find out that?

    That's a harder question and it depends on what architecture you are running on. ps under *nix will be able to show if you have multiple threads in the run queue but even then it may not show that they are actually executing in multiple CPUs.

    0 讨论(0)
  • 2021-01-17 21:29

    Usually gc is running in a separate thread. But usually it doesn't make any significant difference. That's all.

    0 讨论(0)
  • 2021-01-17 21:33

    Your own code will not run on multiple cores if it is by definition single threaded. No single threaded application can run simultaneously on multiple cores - unless your using underluing multithreaded calls/libraries without knowing.

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