Java Map的持久化存储:MapDB
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();
本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!