public class RuntimeUtils {
/**
* 获取系统运行时信息
*/
public static void getSystemOperationInformation() {
//获取当前程序运行时
Runtime runtime = Runtime.getRuntime();
//打印处理器信息
System.out.println("cpu逻辑核心:" + runtime.availableProcessors());
System.out.printf("虚拟机最大内存:" + runtime.maxMemory() + "Byte %.2fM\n", runtime.maxMemory() / 1024 / 1024d);
System.out.printf("虚拟机总共内存:" + runtime.totalMemory() + "Byte %.2fM\n", runtime.totalMemory() / 1024 / 1024d);
System.out.printf("虚拟机剩余内存:" + runtime.freeMemory() + "Byte %.2fM\n", runtime.freeMemory() / 1024 / 1024d);
}
public static void main(String[] args) throws IOException {
RuntimeUtils.getSystemOperationInformation();
}
}
获取JAVA虚拟机运行CPU和内存信息
最新推荐文章于 2022-06-05 20:35:25 发布