Reputation: 49
I have some confusion regarding Multithreading in java.
Let say I have 3 CPU having following details
CPU 1 : Having 2 Core CPU 2 : Having 2 Core CPU 3 : Having 1 Core
So I have 3 CPU with the 5 Core in it.
Now I want to execute the 5 thread.
public static void main(String[] args) {
Thread threadA = new CounterThread();
Thread threadB = new CounterThread();
Thread threadC = new CounterThread();
Thread threadD = new CounterThread();
Thread threadE = new CounterThread();
threadA.start();
threadB.start();
threadC.start();
threadD.start();
threadE.start();
}
So once that main program get executed. will it run on all different 5 Core ??
if it is yes then who is handling to pass the request to different core and how ?
Could someone please elaborate on this.
Thanks in advance
Upvotes: 1
Views: 65
Reputation: 533492
So once that main program get executed. will it run on all different 5 Core ??
It is possible, but there is no way in pure Java to control this. If the thread block they could all run on the same core.
if it is yes then who is handling to pass the request to different core and how ?
There is no concept of a request at the hardware level, all you have is memory which need to updated in a thread safe manner. This allows you to build data structure like thread safe queue which you can pass messages which contain a request.
is all scheduling decided by OS not JVM
If you have native threads, the OS does everything. The JVM makes the right systems calls to make it happen.
Upvotes: 2