How to use getsystemcpuload() in JMX

Hello, I can't use getprocesscputime() or getprocesscpuload() or getsystemcpuload() in my java program I have used the following

ManagementFactory. getOperatingSystemMXBean().getProcesscpuTime();

The same is true

( (OperatingSystemMXBean) getOperatingSystemMXBean() ).getProcesscpuTime()

But no display error like method getprocesscputime () was found I include the following header files That's not enough, or I need to use it again?

import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;

Anyone can advise me how to use these methods I'm using jdk1 6. My code is as follows

import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class printUsage {

public static void main(String[] args) {
OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();

System.out.println("getcpuProcessTime()" + " = " + operatingSystemMXBean.getProcesscpuTime());
System.out.println("getcpuProcessTime()" + " = " + operatingSystemMXBean.getSystemcpuLoad());
System.out.println("getcpuProcessTime()" + " = " + operatingSystemMXBean.getProcesscpuLoad());
}

}

Solution

Import one of the following

import com.sun.management.OperatingSystemMXBean;

no

import java.lang.management.OperatingSystemMXBean;

Use the following code

OperatingSystemMXBean operatingSystemMXBean = (com.sun.management.OperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean();

I used this code to get valid results

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>