how to make Java use all CPU power on a machine?

微笑、不失礼 提交于 2019-12-04 15:13:52

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.

If your program is not explicitly multi threaded (you don't start any thread yourself) then the only reason why it can utilize more than one core is because you are using some functionality of a library which ends up delegating work to a thread pool. Apparently you do not have much control over that so you can't make it work more necessarily.

In regards to utilizing all the CPUs in your S3 instance: You could start your program multiple times (e.g. 33 times if you have 33 CPUs). If that is not possible you will have to find out which part of your processing creates work on the thread pool and change your program so it does more of that (in parallel).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!