本文共 690 字,大约阅读时间需要 2 分钟。
System类在Java编程中扮演着重要角色,提供了丰富的系统级方法
范例:操作耗时的统计
package Java基础类库;public class Runtime类 { public static void main(String[] args) { long start = System.currentTimeMillis();//获取开始的时间 System.out.println("----------用for循环产生大量垃圾----------"); String str =""; for(int x= 0;x<30000;x++) { str+=x; } long end = System.currentTimeMillis();//获取结束的时间 System.out.println("耗时为:"+(end-start)); }}
----------用for循环产生大量垃圾----------
耗时为:1232
在System类中,gc()方法仅作为对Runtime类的gc()方法调用
该方法主要用于清除不再被引用的一部分内存
转载地址:http://pgwe.baihongyu.com/