Thursday, December 11, 2014

Performance comparison of SynchronizedHashMap and ConcurrentHashMap



Recently we had conducted a test for performance comparison of SynchronizedHashMap and ConcurrentHashMap. While both collections are thread safe implementation of Map interface but our study has shown that ConcurrentHashMap is recommended when asked for better performance.

In SynchronizedHashMap , each method is synchronized using an object level lock so get and put method acquire a lock in SyncMap. Locking the entire collection produce performance overhead. While one thread hold the lock no other thread can use the collection.

On the other side, in ConcurrentHashMap there is no object level locking instead it provides locking at hashmap bucket level. Only write operation is synchronized in case of ConcurrentHashMap.

Performance Comparison:



1 comment: