美文网首页
Runtime类

Runtime类

作者: 廷裕同学 | 来源:发表于2020-01-09 15:08 被阅读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
    

    相关文章

      网友评论

          本文标题:Runtime类

          本文链接:https://www.haomeiwen.com/subject/bnvyactx.html