Processor decimal percentage problem - JAVA

Asked

Viewed 76 times

0

Okay, guys, here’s the thing, I developed a code to pick up the percentage used by my processor core application:

private String getCPULoad() {
    OperatingSystemMXBean osBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
    DecimalFormat df = new DecimalFormat("#.##");
    return (df.format(osBean.getProcessCpuLoad())) + "%";
}

In theory he should give me back the percentage, because well he returns it, only in the wrong way, for example: when all the cores are used at 100%, he should return me the percentage "100%", but instead he returns me 0,1%, could someone tell me what I’m doing wrong?

1 answer

0

According to the documentation, the method getProcessCpuLoad returns a double between 0.0 and 1.0, so just multiply the value by 100.

  • If the data were actually collected correctly, it would still correspond to 10% CPU (0.1 * 100), which conflicts with the statement that he was using all the cores at 100%

  • In fact it would be multiply by 1000, but for some reason I’m not managing to do this multiplication

Browser other questions tagged

You are not signed in. Login or sign up in order to post.