import java.io.InputStreamReader;<br />import java.io.LineNumberReader;<br />import sun.management.ManagementFactory;<br />import com.sun.management.OperatingSystemMXBean;<br />public class MonitorInfoTest {<br /> public static void main(String[] args)throws Exception {<br /> MonitorServiceManager service = new MonitorServiceManager();<br /> MonitorInfoBean monitorInfo = service.getMonitorInfoBean();<br /> System.out.println("cpu佔有率=" + monitorInfo.getCpuRatio() + "kb");<br /> System.out.println("可使用記憶體=" + monitorInfo.getTotalMemory() + "kb");<br /> System.out.println("剩餘記憶體=" + monitorInfo.getFreeMemory() + "kb");<br /> System.out.println("最大可使用記憶體=" + monitorInfo.getMaxMemory() + "kb");<br /> System.out.println("作業系統=" + monitorInfo.getOsName());<br /> System.out.println("總的實體記憶體=" + monitorInfo.getTotalPhysicalMemorySize() + "kb");<br /> System.out.println("剩餘的實體記憶體=" + monitorInfo.getFreeMemory() + "kb");<br /> System.out.println("已使用的實體記憶體=" + monitorInfo.getUsedMemory() + "kb");<br /> System.out.println("線程總數=" + monitorInfo.getTotalThread() + "條");<br /> }<br />}<br />class MonitorInfoBean{<br /> /** 可使用記憶體. */<br /> private long totalMemory;<br /> /** 剩餘記憶體. */<br /> private long freeMemory;<br /> /** 最大可使用記憶體. */<br /> private long maxMemory;<br /> /** 作業系統. */<br /> private String osName;<br /> /** 總的實體記憶體. */<br /> private long totalPhysicalMemorySize;<br /> /** 剩餘的實體記憶體. */<br /> private long freePhysicalMemorySize;<br /> /** 已使用的實體記憶體. */<br /> private long usedMemory;<br /> /** 線程總數. */<br /> private int totalThread;<br /> /** cpu使用率. */<br /> private double cpuRatio;<br /> /*產生get和set....*/<br />}