/*
 * 一个jvm对应一个Runtime类
 **/


public class RuntimeDemo1 {

    public static void main(String args[])
    {
        //创建一个Runtime对象
        Runtime run=Runtime.getRuntime();
        try {
            //执行本地程序得到线程
            //Process pro=run.exec("freecell.exe");
            //Thread.sleep(2000);
            //关闭本地程序
            //pro.destroy();
            System.out.println("最大的可用内存:"+run.maxMemory());
            System.out.println("空闲的内存空间:"+run.freeMemory());
            System.out.println("总共内存空间:"+run.totalMemory());
            //消耗内存
            String i="";
            for(int j=0;j<Integer.MAX_VALUE;j++)
            {
                i+=j;
            }
            System.out.println(i);
            //进行垃圾收集
            run.gc();
            //运行后的内存空间
            System.out.println("最大的可用内存:"+run.maxMemory());
            System.out.println("空闲的内存空间:"+run.freeMemory());
            System.out.println("总共内存空间:"+run.totalMemory());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

posted on 2011-01-21 20:02  魔战  阅读(260)  评论(0编辑  收藏  举报