tags:

views:

359

answers:

1

Hi,

with

Runtime.getRuntime().availableProcessors();

I can get the numbers of CPU avaiable.

But how can I get their clock frequency?

I was searching for a os-indipendent solution.

+5  A: 

There is no feature available in the Java SE API which will return the frequency of the CPU.

Also, the Runtime.availableProcessors method returns the number of processors available to the Java virtual machine at the time the method is called, so it won't necessarily return the number of actual processors in a system.

From the Java API Specification for the Runtime.availableProcessors method:

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.

In order to obtain such information, most likely, one would have to make calls the operating system using native calls via Java Native Interface (JNI).

coobird
Thank's. Very clear. I was searching for native method, but if doesn't exist I will study JNI. ;)
THeK3nger