1.

Why Concurrenthashmap Is Faster Than Hashtable In Java?

Answer»

In HashTable each method is synchronized on a single lock which means at any given time only one thread can enter any method. 

ConcurrentHashMap uses separate lock for separate buckets thus locking only a portion of the Map. By DEFAULT there are 16 buckets and also separate locks for separate buckets. So the default CONCURRENCY level is 16. Thus theoretically at any given time 16 threads can access separate buckets without blocking which IMPROVES the performance of the ConcurrentHashMap.

In ConcurrentHashMap performance is further improved by providing read access concurrently without any blocking. Retrieval operations (including get) generally do not block, so may OVERLAP with update operations (including put and remove).

In HashTable each method is synchronized on a single lock which means at any given time only one thread can enter any method. 

ConcurrentHashMap uses separate lock for separate buckets thus locking only a portion of the Map. By default there are 16 buckets and also separate locks for separate buckets. So the default concurrency level is 16. Thus theoretically at any given time 16 threads can access separate buckets without blocking which improves the performance of the ConcurrentHashMap.

In ConcurrentHashMap performance is further improved by providing read access concurrently without any blocking. Retrieval operations (including get) generally do not block, so may overlap with update operations (including put and remove).



Discussion

No Comment Found