JAVA作业,GC的效果
2005-09-12 13:59
399 查看
package demo;
public class DemoFinal {
private static Runtime runtime = Runtime.getRuntime();
private static boolean finalized;
private int buffer[] = new int[10000];
protected static long printFreeMemory(String prefix) {
long freeMemory = runtime.freeMemory();
System.out.print(prefix);
System.out.println("The free memory is " + freeMemory);
return freeMemory;
}
public static void main(String args[]) {
DemoFinal demoFinal = new DemoFinal();
printFreeMemory("");
demoFinal = null;
long time = System.currentTimeMillis();
runtime.gc();
while (finalized) ; //waiting for the finalize executed
System.out.print("The gc Action costs ");
System.out.print(System.currentTimeMillis()-time);
System.out.print(" Milliseconds");
}
protected void finalize() throws Throwable {
printFreeMemory("After GC,");
finalized = true;
}
}
public class DemoFinal {
private static Runtime runtime = Runtime.getRuntime();
private static boolean finalized;
private int buffer[] = new int[10000];
protected static long printFreeMemory(String prefix) {
long freeMemory = runtime.freeMemory();
System.out.print(prefix);
System.out.println("The free memory is " + freeMemory);
return freeMemory;
}
public static void main(String args[]) {
DemoFinal demoFinal = new DemoFinal();
printFreeMemory("");
demoFinal = null;
long time = System.currentTimeMillis();
runtime.gc();
while (finalized) ; //waiting for the finalize executed
System.out.print("The gc Action costs ");
System.out.print(System.currentTimeMillis()-time);
System.out.print(" Milliseconds");
}
protected void finalize() throws Throwable {
printFreeMemory("After GC,");
finalized = true;
}
}
相关文章推荐
- 第六次java作业
- Java 内存区域和GC机制
- 理解Java的GC日志
- Java第一次作业(2)
- java中垃圾回收机制(GC)
- JAVA第四次作业(2接口练习题)
- java GC 回收机制 转
- java作业16027240048
- Java实现窗体中角色逐渐风化效果
- 成为Java GC专家(3)—如何优化Java垃圾回收机制
- WEEK9 JAVA作业
- Java堆分布以及GC分类
- java第一次作业-----源代码计数器
- Java的GC回收机制
- Java GC 日志详解
- 02-Reference & GC 分类: JVM Java 2015-07-16 19:17 92人阅读 评论(0) 收藏
- JAVA作业——输入指定文件,计算代码行数
- Java 内存区域和GC机制
- java的GC机制--java对象的访问方
- JAVA作业(5)