Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 581
user697911 Avatar asked Apr 10 '13 20:04

user697911


People also ask

Can a single thread run on multiple cores?

About core activityIt's not possible to split a single thread across multiple cores, although a single core may run multiple threads at the same time. This is one reason that you may sometimes see uneven load distributions across the available cores on your computer.

Do multiple threads use multiple cores?

Multithreading is a form of parallelization or dividing up work for simultaneous processing. Instead of giving a large workload to a single core, threaded programs split the work into multiple software threads. These threads are processed in parallel by different CPU cores to save time.

What is a single thread software?

single thread performance is the amount of work completed by some software that runs as a single stream of instructions in a certain amount of time.


2 Answers

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.

like image 65
Gray Avatar answered Sep 18 '22 15:09

Gray


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.

like image 23
Menelaos Avatar answered Sep 21 '22 15:09

Menelaos