dreadiscool
dreadiscool

Reputation: 1598

Is ConcurrentHashMap good for rapidly updating concurrent data structures?

I'm designing an application that maps an IP address to certain info about that IP address. Currently, I have the information stored in a ConcurrentHashMap. The list of keys could change frequently, so I grab the latest copy of the list and update it once every minute.

However, I could possibly be querying this data structure a few thousand times a minute. Does it make sense to use a ConcurrentHashMap? Would there be a significant delay (larger than 1ms) when the list is being updated? There could be up to 1000 items in the list.

Thanks for your help!

Upvotes: 1

Views: 493

Answers (2)

cristi
cristi

Reputation: 361

You can search about ConcurrentHashMap, in the documentation, and you will see that the retrieval operations generally do not block, so they act just like in a normal HashMap. Retrieval operations includes remove and get. You said that the list of keys could change frequently, so yes, I recommend you to use ConcurrentHashMap. Here is the documentation: http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentHashMap.html

Upvotes: 3

Strikeskids
Strikeskids

Reputation: 4052

With so few items, it's very unlikely that there will be any delay. A good baseline with significant overhead for error is approximately 10 million operations per second when looking at big-O notation.

Given the fact that you are only querying a few thousand times a minute and a hash map is O(1), there shouldn't be any problem.

Upvotes: 0

Related Questions