Replacing Hashtable With ConcurrentHashMap in Java

A ConcurrentHashMap can be replaced with Hashtable in Java.

But it requires careful observation, since locking behavior of Hashtable is different than that of ConcurrentHashmap.

A Hashtable locks whole Map instead of a portion of Map. Compound operations like if(Hashtable.get(key) == null) put(key, value) work in Hashtable but not in ConcurrentHashMap.

In a ConcurrentHashMap we use putIfAbsent() method for such a scenario



You May Interest

What is the Difference Between init-param and context-param in JS ...

What are the Differences Between Internal and External Iterator i ...

What are the Different Types of Events Provided by Spring Framewo ...

How Can You Make an Object Eligible for Garbage Collection in Jav ...

How Will You Define the Scope of a Bean in Spring ?