Java: multi-threaded maps: how do the implementations compare?

Posted by user346629 on Stack Overflow See other posts from Stack Overflow or by user346629
Published on 2010-05-20T23:22:45Z Indexed on 2010/05/20 23:40 UTC
Read the original article Hit count: 155

Filed under:
|
|

I'm looking for a good hash map implementation. Specifically, one that's good for creating a large number of maps, most of them small. So memory is an issue. It should be thread-safe (though losing the odd put might be an OK compromise in return for better performance), and fast for both get and put. And I'd also like the moon on a stick, please, with a side-order of justice.

The options I know are:

  • HashMap. Disastrously un-thread safe.

  • ConcurrentHashMap. My first choice, but this has a hefty memory footprint - about 2k per instance.

  • Collections.sychronizedMap(HashMap). That's working OK for me, but I'm sure there must be faster alternatives.

  • Trove or Colt - I think neither of these are thread-safe, but perhaps the code could be adapted to be thread safe.

Any others? Any advice on what beats what when? Any really good new hash map algorithms that Java could use an implementation of?

Thanks in advance for your input!

© Stack Overflow or respective owner

Related posts about java

Related posts about hashmap