Runtime类

2020-01-09  本文已影响0人  廷裕同学

Runtime类:代表了当前程序的运行环境
Runtime对象需要掌握的方法

-public Process exec(String command)
    执行指令路径下的可执行文件。
-long maxMemory()
    返回虚拟机试图使用的最大内存
-long totalMemory()
    返回虚拟机管理的内存总量
-long freeMemory()
    当前空闲的内存
import java.io.IOException;
public class Demo2 {

    public static void main(String args[]){
        Runtime rt = Runtime.getRuntime();
        System.out.println("试图使用的最大内存:" + rt.maxMemory()/1024/1024 + "M");
        System.out.println("实际管理的内存:" + rt.totalMemory()/1024/1024+"M");
        System.out.println("空闲的内存:" + rt.freeMemory()/1024/1024+"M");
//        try{
//            Thread.sleep(5000);
//            rt.exec("C:\\Windows\\notepad.exe");
//        }catch (Exception e){
//            System.out.println(e.getMessage());
////            throw e;
//        }

    }
}

控制台输出

试图使用的最大内存:4096M
实际管理的内存:258M
空闲的内存:255M
上一篇 下一篇

猜你喜欢

热点阅读