Consider these two situations:
- a map which you are going to populate once at the beginning and then will be accessed from many different threads.
- a map which you are going to use as cache that will be accessed from many different threads. you would like to avoid computing the result that will be stored in the map unless it is missing, the get-computation-store block will be synchronized. (and the map will not otherwise be used)
In either of these cases, does ConcurrentHashMap
offer you anything additional in terms of thread safety above an ordinary HashMap
?