最近在做一个监控系统,探针要在业务系统中创建一个缓存,为了估量探针对业务系统的影响,模拟探针的动作,写了个小程序评估一下。
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class TestMemory {
private final static int _SIZE = 3000;
public static void main( String [] args ){
System.out.println("创建对象前的内存:"+Runtime.getRuntime().freeMemory()/1024/1024+"M");
System.out.println("----------------------------------------------");
HashMap map = new HashMap(_SIZE);
HashMap childMap = null;
List list = null;
for (int da = 0; da < _SIZE; da++) {
list = new ArrayList();
for (int tonglei = 0; tonglei < 23; tonglei++) {
childMap = new HashMap(23);
childMap.put("http", "http://10.10.5.9/kpoa/app/hoa_news.nsf/FM_HomePagePortlet?openform&Class=%E9%80%9A%E7%9F%A5%2F%E5%85%AC%E5%8F%B8%E9%80%9A%E7%9F%A5");
list.add(childMap);
}
map.put("allinfo", list);
}
System.out.println("创建对象后的内存:"+Runtime.getRuntime().freeMemory()/1024/1024+"M");
}
}