Java Map的持久化存储:MapDB

jopen 12年前

MapDB 提供了并发的 TreeMap 和 HashMap ,使用基于磁盘的存储。快速、可伸缩性以及易用。

示例代码:

import org.mapdb.*;    // configure and open database using builder pattern.  // all options are available with code auto-completion.  DB db = DBMaker.newFileDB(new File("testdb"))                 .closeOnJvmShutdown()                 .encryptionEnable("password")                 .make();    // open existing an collection (or create new)  ConcurrentNavigableMap<Integer,String> map = db.getTreeMap("collectionName");    map.put(1, "one");  map.put(2, "two");  // map.keySet() is now [1,2]    db.commit();  //persist changes into disk    map.put(3, "three");  // map.keySet() is now [1,2,3]  db.rollback(); //revert recent changes  // map.keySet() is now [1,2]    db.close();

项目主页:http://www.open-open.com/lib/view/home/1362537185748