硬盘map

/*
* Copyright (c) 2011 Skyon Technology Ltd.
* All rights reserved.
*
* project: java1
* create: May 12, 2011 4:04:03 PM
* cvs: $Id: $
*/
package skyon.util.map;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import com.alok.diskmap.DiskBackedMap;
/**
* TODO map测试.
* @author xinglj 
* @version $Revision:$
*/
public class TestDiskBackedMap {
public static void main(String[] args) throws Throwable {
test1();
// test2();
}
/**
* @throws Throwable 
* 
*/
private static void test1() throws Throwable {
System.out.println("maxMemo "+Runtime.getRuntime().maxMemory()/1024000);
System.out.println("totalMemo "+Runtime.getRuntime().totalMemory()/1024000);
System.out.println("freeMemo "+Runtime.getRuntime().freeMemory()/1024000);
DiskBackedMap<String, String> diskBackedMap = new DiskBackedMap<String, String>("c:/temp");
Map<String, String> m= diskBackedMap;
testmap(m);

diskBackedMap.finalize();

}
private static void test2() throws Throwable {
System.out.println("maxMemo "+Runtime.getRuntime().maxMemory()/1024000);
System.out.println("totalMemo "+Runtime.getRuntime().totalMemory()/1024000);
System.out.println("freeMemo "+Runtime.getRuntime().freeMemory()/1024000);

try {
Map<String, String> m=
new HashMap<String, String>();
// diskBackedMap;
testmap(m);
} catch (Exception e) {

e.printStackTrace();
System.gc();
}



}
/**
* @param m
*/
private static void testmap(Map<String, String> m) {
int i=0;
try {
StringBuffer buf=new StringBuffer("你好你好");
String buf2=new StringBuffer("你好你好").toString();
System.out.println("begin to write...");
int length = 500000;
for(;i<length;i++){
m.put(""+i, new String(buf.toString()+i));
// buf2 +=buf2;
m.put(2*i+"", buf2);
}

System.out.println("begin to read...");
for(i=0;i<length;i++)
m.get(""+i);
System.out.println("read end.");
System.out.println("test ok?"+m.get("0").equals("你好你好0"));
System.out.println("test ok?"+m.get("20000").equals("你好你好20000"));
System.out.println("test ok?"+m.get("49999").equals("你好你好49999"));
} catch (OutOfMemoryError e) {
System.out.println("for loop to "+i);
e.printStackTrace();
}
System.out.println("maxMemo "+Runtime.getRuntime().maxMemory()/1024000);
System.out.println("totalMemo "+Runtime.getRuntime().totalMemory()/1024000);
System.out.println("freeMemo "+Runtime.getRuntime().freeMemory()/1024000);
m.clear();
}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值