InterviewSolution
| 1. |
What Is Concurrenthashmap In Java? |
|
Answer» ConcurrentHashMap is also a hash BASED map like HashMap, how it differs is the locking strategy used by ConcurrentHashMap. Unlike HashTable (or synchronized HashMap) it doesn't synchronize EVERY METHOD on a common lock. ConcurrentHashMap uses separate lock for separate buckets thus locking only a portion of the Map. That way ConcurrentHashMap depite being a THREAD safe alternative to HashTable gives MUCH better performance. ConcurrentHashMap is also a hash based map like HashMap, how it differs is the locking strategy used by ConcurrentHashMap. Unlike HashTable (or synchronized HashMap) it doesn't synchronize every method on a common lock. ConcurrentHashMap uses separate lock for separate buckets thus locking only a portion of the Map. That way ConcurrentHashMap depite being a thread safe alternative to HashTable gives much better performance. |
|