1.

What Is The Difference Between Hashmap And Concurrenthashmap In Java?

Answer»
  • CONCURRENTHASHMAP is thread safe and fit for use in a multi-threaded environment whereas HashMap is not thread safe.
  • HashMap can be synchronized using the Collections.synchronizedMap() method but that synchronizes all the methods of the HashMap and EFFECTIVELY REDUCES it to a DATA structure where one thread can enter at a time.

In ConcurrentHashMap synchronization is done a little differently. Rather than locking every method on a common lock, ConcurrentHashMap uses separate lock for separate buckets thus locking only a portion of the Map.

In ConcurrentHashMap synchronization is done a little differently. Rather than locking every method on a common lock, ConcurrentHashMap uses separate lock for separate buckets thus locking only a portion of the Map.



Discussion

No Comment Found