Java: Kernels available for JVM?

In Java, there is the Runtime.getRuntime().availableProcessors() method, which has the following Javadoc:

Returns the number of processors available for the Java virtual machine. This value may change during a particular virtual machine call.

How can I change the value? In what circumstances would there be fewer processors for the JVM than physically installed, for example?

Jonas

+5
java jvm core processors
source share
4 answers

The Linux taskset(1) command can be used to force processes to use a specific processor or specific processor sets; It’s pretty easy to modify a running program to make it work with one or more processors. For example,

 taskset -p `pidof java` --cpu-list 0,5,7,9-11 
+10
source share

On Windows, you can change the number of cores that an application can use with some simple properties. In virtualized environments, you can also restrict the kernels to a virtual machine so that you only see the kernels that the VM sees. And on Linux / Unix, you can set the kernel proximity so that applications or users cannot use all the kernels, so it is possible that you may have more kernels than they are visible to the JVM.

Note. This is useful for machines that run several tasks, where you do not need a high resource conflict, and you want to underestimate (or even reassign) resources.

+5
source share

On some hardware (servers), it is possible to switch processors without rebooting the system. This can lead to a change in the number of processors. Although the more common reason is that sysadmin changed the processor scheduling policy.

+2
source share

You can configure the resources available for java applications with the parameters of the java command. I don’t really know the exact name of the switches, but you can configure a bunch of things.

Why are you giving fewer processors to the JVM instance? It depends! perhaps you place cats and want to allocate resources available to your customers.

Hope this helps.

+1
source share

All Articles