java监视jvm内存容量,获取空闲容量,总容量及其使用所占百分比
package com.zr.demo01;
/**
* 监视jvm内存容量,获取空闲容量,总容量及其使用所占百分比
* @author ZR
*
*/
public class Thirteenth {
public static void main(String[] args) {
//空闲内存
int free=(int)Runtime.getRuntime().freeMemory()/1024;
//总内存
int total=(int)Runtime.getRuntime().totalMemory()/1024;
//使用占百分比
String status=(total-free)*100/total+"%";
System.out.println("剩余内存:"+free+"KB");//剩余内存:127014KB
System.out.println("总内存:"+total+"KB");//总内存:129024KB
System.out.println("使用占百分比:"+status);//使用占百分比:1%
}
}