I sometimes write code in Java, and I noticed that sometimes it uses more than 100% CPU on a multicore machine. I am now running some code on a multicore machine that has 33 CPUs (Amazon’s EC2), and I want to make my Java process use all CPUs available, so that it will have very high utilization of the machine. Is that possible, or is it left up to Java to decide when to use more than 100% CPU? I do not wish to change the code to use multithreading.
Share
Without using multiple threads or processes (or something other than the one process running), you won’t be able to achieve n*100% usage on a n-core machine.
The operating system decides to run each of your user programs on a single thread, unless a request for more is made. Without that request, the OS will happily let you run your code in a single thread, potentially maxing out an entire CPU’s cycles – but it leaves the others open.