Map使用操作系统内存的情况
public static void main(String[] args) { System.out.println("程序启动-->可用内存:"+(getSystemMem()/1024/1024)+"M"); Long systemMem = getSystemMem(); Map<byte[],Byte> map = new HashMap<byte[], Byte>(); for(int i=0;i<100000000;i++){ map.put(StringUtils.md5("http://www.baidu.com"+i),Byte.parseByte("1")); if(i%100000==99999){ System.out.println("存储"+(i+1)+"后,使用内存:"+((systemMem-getSystemMem())/1024/1024)+"M"); } } } public static Long getSystemMem(){ OperatingSystemMXBean osmb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); return osmb.getFreePhysicalMemorySize(); }