user697911
user697911

Reputation: 10531

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?

Upvotes: 9

Views: 5228

Answers (3)

Gray
Gray

Reputation: 116858

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.

Upvotes: 15

Menelaos
Menelaos

Reputation: 25725

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.

Upvotes: 1

kan
kan

Reputation: 28951

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

Upvotes: 0

Related Questions