Java: multi-threaded cards: how to compare implementations?

I am looking for a good hash map implementation. In particular, it is good for creating a large number of cards, most of which are small. So memory is a problem. It should be thread safe (although losing odd input can be a compromise of OK in exchange for better performance), and quickly for both receiving and input. And I would also like the moon on a stick, please, with a side order of justice.

Options I know:

  • HashMap It is amazingly safe to disable the stream.

  • ConcurrentHashMap. My first choice, but it has a large amount of memory - about 2 thousand per instance.

  • Collections.sychronizedMap (HashMap). This works fine for me, but I'm sure there should be faster alternatives.

  • Trove or Colt - I think none of them are thread safe, but perhaps the code can be adapted to ensure thread safety.

Any others? Any advice on what hits when? Any really good new hash map algorithms that Java can use to implement?

Thank you in advance for your entry!

+6
java hashmap multithreading
source share
6 answers

Collections.synchronizedMap() just makes all Map methods synchronized .

ConcurrentMap is really the interface you want, and there are several implementations (for example, ConcurrentHashMap , ConcurrentSkipList ). It has several operations that Map are not important for thread safe operations. In addition, it is more granular than a synchronized Map , since the operation blocks only a fragment of the backup data structure, and not the whole thing.

+6
source share

I have no experience with the following, but I worked with a project once that swore to Javolution for real-time and memory tasks.

I noticed that the API has FastMap , which claims to be thread safe. As I said, I have no idea if this is good for you, but it's worth a look:

API for FastMap

Javolution home

+3
source share

Google Collection MapMaker seems to be able to do the job as well.

+3
source share

It is very surprising that he has a print of 2 thousand feet !! How to make the ConcurrentHashMap concurrency value lower (e.g. 2-3) and optimize its initial size (= make it smaller).

I don’t know where this memory consumption comes from, but maybe it has something to do with maintaining striped locks. If you omit the concurrency parameter, it will have less.

If you need good performance with ready-made thread safety, ConcurrentHashMap really nice.

+2
source share

Well, Apache Mahout has a shard of Colt. This is still not in the current business. What is wrong with synchronized block code protection? Do you expect some devilishly complex scheme that contains locks for less granularity than put or get ?

If you can write the code, please enter it in Mahout.

0
source share

It's worth taking a look at persistent hash maps in Clojure.

These are immutable, thread safe data structures with performance comparable to classic Java HashMaps. You will obviously need to wrap them if you want to change the map, but this should not be difficult.

http://clojure.org/data_structures

0
source share

All Articles