目录
Runtime类
1.概述
2.常见方法
(1).getRuntime返回环境对象
(2).exit停止虚拟机
(3).availableProcessors返回线程数
(4). maxMemory返回获得最大内存
(5).totalMemory返回已经获得内存
(6).freeMemory返回剩余内存
(7).exec运行cmd命令
Runtime表示Java中运行时对象,可以获取到程序运行时设计到的一些信息
当前系统的运行环境对象
public static Runtime getRuntime()
停止虚拟机
public void exit(int status)
事实上System.exit的底层源码就是Runtime里的exit方法
状态码:
获得CPU的线程数
public int availableProcessors()
JVM能从系统中获取总内存大小(单位byte)
public long maxMemory()
JVM已经从系统中获取总内存大小(单位byte)
public long totalMemory()
JVM剩余内存大小(单位byte)
public long freeMemory()
运行cmd命令
public Process exec(String command)
上述代码能直接打开记事本
上述代码会令计算机3600秒后关机
注意: