Alternative getSystemLoadAverage () for Windows?

I am working on some code to control the loading of Cpu using Java. I use the following code in my application to get the system boot

public static double getCPULoad() { OperatingSystemMXBean osMBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); double load = osMBean.getSystemLoadAverage(); return load; } 

But the windows returns a negative value (-1.0). Is there any way to solve this problem?

+5
source share
1 answer

Read this blog . This is not an official solution, but when using com.sun.management.OperatingSystemMXBean instead of java.lang.management.OperatingSystemMXBean two methods getSystemCpuLoad() and getProcessCpuLoad() .

+2
source

Source: https://habr.com/ru/post/1206665/


All Articles