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.
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.
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.
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With