Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java VM - Eclipse using my cores?

I have this question about the JVM running my Java code. My friend has a 2.4 or 2.5GHz dual core while I have a 2GHz quad core. Now my question is: does Java use all the cores or just one? My friend thought Java used 1 core and so he would have the better running time because his core has a higher clock rate than mine.

like image 723
user1903753 Avatar asked Dec 14 '12 10:12

user1903753


People also ask

Does Java automatically use multiple cores?

Java will benefit from multiple cores, if the OS distribute threads over the available processors. JVM itself do not do anything special to get its threads scheduled evenly across multiple cores.

Does Java use all CPU cores?

So each process still won't be able to use all CPU cores. Java has an option to ignore this whole Docker mechanism, and override how many cores should be returned from availableProcessors() . You can specify the value you want to return with the -XX:ActiveProcessorCount=nn JDK option, as described here.

How do I know if all my cores are being used?

Right-click the taskbar and select Task Manager from the context menu. Go to the Performance tab and select CPU. Right-click on the graph in the right pane and select Change graph to>Logical processors. You will see a graph for each core and its usage.


1 Answers

The JVM itself uses several threads, which will most likely use several cores (depending on the mood of the OS scheduler).

Your program uses as many threads as you ask it to use. If your code is single-threaded, it will be sequential and will not benefit from your multi-core architecture (note however, that your single thread might use more than one core, but not at the same time).

like image 121
assylias Avatar answered Sep 20 '22 01:09

assylias