简体   繁体   English

基于文件的java.util.Map的现有实现

[英]Existing File based implementation of java.util.Map

I'm working on a project that uses custom Map<String, Entry> (where Entry is a pair of ints) implementation based on B-tree to store from 10 to 100 millions of records, the code for this class is slow and dirty. 我正在使用基于B树的自定义Map <String,Entry>(其中Entry是一对int)实现的项目来存储10到1亿条记录,此类的代码缓慢且肮脏。 I need efficient implementation of the Map, which uses a file for storage and a small amount of memory. 我需要Map的高效实现,该Map使用一个文件进行存储并占用少量内存。

I searched and found that Java Edition Of Berkeley DB has java.util.Collection API (including Map), but it seems superfluous to use a fully fledged database for this purpose (it uses directory with many files, has several additional threads for management). 我搜索发现Berkeley DB的Java版具有java.util.Collection API(包括Map),但是为此目的使用功能完备的数据库似乎是多余的(它使用包含许多文件的目录,并且具有多个用于管理的线程) 。 Is there a simpler solution? 有没有更简单的解决方案?

I had this very same problem recently and looked at everything under the sun, including NoSQL and caches. 我最近也遇到了同样的问题,并研究了阳光下的所有事物,包括NoSQL和缓存。 You want a disk/file based/backed hashmap. 您需要基于磁盘/文件/支持的哈希图。

Berkeley DB Java Edition is by far the best. 到目前为止,伯克利DB Java版是最好的。 It's fast, scalable, and complete, but you can't distribute it to clients without distributing your source code or buying the commercial version from Oracle. 它是快速,可扩展和完整的,但是如果不分发源代码或从Oracle购买商业版本,就无法将其分发给客户端。

The only other choice, besides reinventing the wheel, is JDBM2. 除了重新发明轮子之外,唯一的选择是JDBM2。 It also has a hashmap and a tree map. 它还具有一个哈希图和一个树图。 You are responsible for regularly flushing to disk to prevent OutOfMemoryError and it isn't near as fast as Berkeley DB but it is a very good 2nd choice. 您有责任定期刷新到磁盘以防止OutOfMemoryError,它的速度不及Berkeley DB快,但这是第二种很好的选择。

Take a look at Kyoto Cabininet , a disk-backed DBM implementation. 看一下磁盘支持的DBM实现Kyoto Cabininet I've used the previous version, Tokyo Cabinet - it was dead easy to use, basically just like a native Map , and very fast. 我使用了以前的版本“ Tokyo Cabinet” ,它非常易于使用,基本上就像本地Map ,而且速度非常快。

JDBM是一个轻量级的纯Java B-Tree实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM