Thursday, June 18, 2009

Concurrent HashMap vs HashMap

So today i looked into these two Map types to use in the multi threaded application im working on. It was really confusing to understand the exact differences between the two but after some research this is my vedict;

Use ConcurrentHashMap if you only want to concurrently add and remove values and do not want to access the map while concurrent additions and modifications go on. But if you do want to access data while concurrent additions and modifications are going on then its better to use Collections.synchronizedHashMap() and make the iteration code block thread safe in order to avoid race conditions.

No comments:

Post a Comment