17

Berkeley DB would be the best choice probably but I can't use it due to licensing issues.

Are there any alternatives?

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
Roman
  • 64,384
  • 92
  • 238
  • 332
  • @Stephen C: you are welcome to edit and provide better explanation. About "responding sarcastically": it sounds strange for me that alternative to Berkeley DB is HashMap. – Roman Apr 04 '10 at 15:27
  • 2
    upvoting - question seems legit, and not that much sarcasm going around. Given, question could have stated from the start that hashmaps would not cut it. – tucuxi Apr 04 '10 at 21:45
  • OK @Roman ... what **DO** you mean by "//sarcasam" in your comment below?? – Stephen C Apr 05 '10 at 00:30
  • Why not check nosql-database.org --> Key Value / Store section and have an answer for yourself. Using IMDG , also a [Key Value Store](http://blogs.alachisoft.com/tayzgrid/using-an-in-memory-key-value-store-to-scale-java-apps/) ,gives you the option to scale – Basit Anwer Dec 16 '15 at 06:47

10 Answers10

8

You can try Hazelcast. Just add hazelcast.jar to your classpath. And start coding

java.util.Map map = Hazelcast.getMap("myMap");

You'll get an in-memory, distributed, dynamically scalable data grid which performs super fast.

om-nom-nom
  • 62,329
  • 13
  • 183
  • 228
Fuad Malikov
  • 2,325
  • 18
  • 20
3

Your question could mean one of two things.

If you mean a data structure for storing key-value pairs, use one of the Map instances that are a standard part of the JDK.

If however you are after an in-memory key-value store then I would suggest taking a look at EHCache or even memcached.

cletus
  • 616,129
  • 168
  • 910
  • 942
3

Chronicle-Map is a strong alternative.

  • Pure Java, simply java.util.Map implementation
  • Stores the data off-heap, optionally persisted to disk via memory-mapped files
  • Open source, permissive Apache 2.0 license
  • Incredibly fast, can manage millions of updates/queries per second (see exact numbers)
leventov
  • 14,760
  • 11
  • 69
  • 98
2

I know this is a two-year old post but I've been messing around with Infinispan recently and I like it so far. I'm not an expert by any means but it was not too difficult for me to set up a distributed cache with a few nodes and I was pulling some data from them in about an hour.

Richard Yhip
  • 106
  • 1
  • 4
2

MapDb is an alternative to Berkley with a friendly Apache 2 license.

  • Provides key-value store via java's Map interface
  • Lightweight (300KB jar)
  • Fast and threadsafe
  • Persists changes to disk if you want to
  • Many other features
Andrejs
  • 26,885
  • 12
  • 107
  • 96
2

HashMap?

Chris Dennett
  • 22,412
  • 8
  • 58
  • 84
  • 1
    It lacks transactions management and possibility to keep some data in the disk and another part in-memory and so on.. //sarcasm – Roman Apr 04 '10 at 15:01
  • Ah, I see :) There was a problem a while back with someone wanting to develop stuff for Android but needed to use a storage-backed hashmap because the size of his data was too large. Something similar, I guess. – Chris Dennett Apr 04 '10 at 15:40
1

jdbm works great for this sort of thing. It's intended for storing on disk in a paged file, provides for basic transaction support (no guarantees on isolation, but ACD are covered). We've used it in a production system with fairly wide deployment and have been quite pleased with the performance, stability, etc...

Kevin Day
  • 16,067
  • 8
  • 44
  • 68
1

Consider using jredis. It's a Java client for Redis, a persistent key-value store. There's also a JDBC driver for it: code.google.com/p/jdbc-redis/.

Nathan Hurst
  • 1,740
  • 14
  • 22
0

I would recommend to try a Redisson. You will able to use distributed and scalable Map or ConcurrentMap and other (Set, List, Queue, Lock ...) implementations on top of high performance key-value Redis server.

Easy example:

Redisson redisson = Redisson.create();

ConcurrentMap<String, SomeObject> map = redisson.getMap("anyMap");

...

redisson.shutdown();
Nikita Koksharov
  • 10,283
  • 1
  • 62
  • 71
0

There are lightweigh or embedded dbs like HSQLDB, Derby, SQLite But like others don't understand why you need a db to store key/values...

Why not a Map? Need to keep key/values on app reboot?

Also it's perhaps not what you need but with html5 on up to date browsers you have localStorage that permits you to store key/values in the browser using javascript.

Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419