Single thread program to make use of multiple cores Single thread program to make use of multiple cores multithreading multithreading

Single thread program to make use of multiple cores


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.


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.


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