Java.lang Runtime
1 Java.lang Runtime介绍
Java Runtime类用于与Java运行时环境进行交互。Java Runtime类提供了用于执行进程,调用GC,获取总内存和可用内存等的方法。java.lang.Runtime类只有一个实例可用于一个Java应用程序。
2 Java.lang Runtime声明
public class Runtime
extends Object
3 Java.lang Runtime方法
4 Java.lang Runtime案例
package com.yiidian;
/**
* 一点教程网: http://www.yiidian.com
*/
public class MemoryTest{
public static void main(String args[])throws Exception{
Runtime r=Runtime.getRuntime();
System.out.println("Total Memory: "+r.totalMemory());
System.out.println("Free Memory: "+r.freeMemory());
for(int i=0;i<10000;i++){
new MemoryTest();
}
System.out.println("After creating 10000 instance, Free Memory: "+r.freeMemory());
System.gc();
System.out.println("After gc(), Free Memory: "+r.freeMemory());
}
}
输出结果为:
Total Memory: 100139008
Free Memory: 99474824
After creating 10000 instance, Free Memory: 99310552
After gc(), Free Memory: 100182832
热门文章
优秀文章