Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

examples of ConcurrentHashMap

I was reading the article "Java theory and practice: Building a better HashMap" that gives an excellent overview about the implementation of ConcurrentHashMap.

I also found some discussions over it on Stackoverflow here.

I question though I had in my mind is "what are the scenarios/applications/places" where ConcurrentHashMap is used.

Thank you

like image 638
daydreamer Avatar asked Dec 29 '22 05:12

daydreamer


2 Answers

You would use a ConcurrentHashMap in the same instances you would use a HashMap, except that you plan on more than one thread using the map.

like image 80
Jeremy Avatar answered Dec 30 '22 19:12

Jeremy


I use it for quick lookup from user ids to user objects in a multi-threaded server for instance.

I have a network-thread, a timer thread for periodical tasks and a thread for handling console input. Multiple threads access the hash map of users, thus it needs to be thread safe.

like image 26
aioobe Avatar answered Dec 30 '22 20:12

aioobe