Java: multi-threaded maps: how do the implementations compare?
Collections.synchronizedMap()
simply makes all the Map
methods synchronized
.
ConcurrentMap
is really the interface you want and there are several implementations (eg ConcurrentHashMap
, ConcurrentSkipList
). It has several operations that Map
doesn't that are important for threadsafe operations. Plus it is more granular than a synchronized Map
as an operation will only lock a slice of the backing data structure rather than the entire thing.
I have no experience of the following, but I worked with a project once who swore by Javolution for real time and memory sensitive tasks.
I notice in the API there is FastMap that claims to be thread safe. As I say, I've no idea if it's any good for you, but worth a look: