Search code examples
javaconcurrenthashmap

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


Solution

  • 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.