Java: Cores available to the JVM?

爷,独闯天下 提交于 2019-12-04 05:23:06

The Linux command taskset(1) can be used to force processes to use a specific CPU or specific sets of CPUs; it is pretty easy to modify a running program to force it to one or more processors. For example,

taskset -p `pidof java` --cpu-list 0,5,7,9-11

In Windows it's possible to change the number of cores an application is allowed to use via some simple properties. In virtualized environments you can also restrict cores to the VM so you only see the cores the VM sees. And in Linux/Unix you can set core affinity so that applications or users can't use all the cores so it's possible that you may have more cores installed than are visible to the JVM.

Note: this is useful for machines running multiple jobs where you don't want high resource contention and you want to underprovision (or even overprovision) resources.

On some hardware (servers), it is possible to hotswap processors without rebooting the system. This may cause the number of processors to change. Although a more common cause is when the sysadmin changed the processor scheduling policy.

You can customize the resources available to the java applications with options on the java command. I actually don't know the exact name of the switches but you can customize a bunch of stuff.

Why would you give less processors to an instance of the JVM? It depends! maybe you're hosting tomcats and want to distribute resources available to your customers.

Hope this helps.

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