How does Java makes use of multiple cores?

Munish Sodhi picture Munish Sodhi · Dec 14, 2010 · Viewed 93k times · Source

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 for high concurrency?

Answer

Emil picture Emil · Dec 14, 2010

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: