Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get max CPU clock in Java

Tags:

java

cpu

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.

like image 255
Davide Aversa Avatar asked Sep 19 '09 15:09

Davide Aversa


1 Answers

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).

like image 119
coobird Avatar answered Oct 26 '22 21:10

coobird