获取Java虚拟机可用的处理器个数

阅读更多

 

如何获取Java虚拟机可用的处理器个数?

 

Runtime类的Native方法#availableProcessors()已经提供了,只要通过Runtme类的实例调用即可。

 

/**
     * Returns the number of processors available to the Java virtual machine.
     *
     * 

This value may change during a particular invocation of the virtual * machine. Applications that are sensitive to the number of available * processors should therefore occasionally poll this property and adjust * their resource usage appropriately.

* * @return the maximum number of processors available to the virtual * machine; never smaller than one * @since 1.4 */ public native int availableProcessors();

 

调用方法:

 

int availableProcessors = Runtime.getRuntime().availableProcessors();

 

你可能感兴趣的:(Java,Runtime,处理器)