How does Java makes use of multiple cores?

前端 未结 4 1316
萌比男神i
萌比男神i 2020-11-27 11:35

A JVM runs in a single process and threads in a JVM share the heap belonging to that process. Then how does JVM make use of multiple cores which provide multiple OS threads

4条回答
  •  春和景丽
    2020-11-27 12:12

    You can make use of multiple cores using multiple threads. But using a higher number of threads than the number of cores present in a machine can simply be a waste of resources. You can use availableProcessors() to get the number of cores.

    In Java 7 there is fork/join framework to make use of multiple cores.

    Related Questions:

    • Is Multi-Threaded algorithm required to make use of Multi-core processors ?
    • Threads per Processor
    • Correctly multithreaded quicksort or mergesort algo in Java?

提交回复
热议问题