Problem with decimal percentage of processor - JAVA

0

Good people, the problem is the following, I developed a code to get the percentage used by my application of the processor cores:

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, well he returns, but in the wrong way, for example: when all cores are used 100%, he should give me the percentage "100%", but Instead he gives me 0.1%, could anyone tell me what I'm doing wrong?

    
asked by anonymous 12.09.2017 / 03:34

1 answer

1

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

    
12.09.2017 / 04:53