This blog is all about to learn Core Java Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.
Previously we have discussed about
what is AbstractMap in java ?
Here, we learn What is ConcurrentHashMap In Java.But before starting we must know what is Map Interface In Java.?
Class ConcurrentHashMap<K,V>
Type Parameters :-
K - the type of keys maintained by this map
V - the type of mapped values
All Implemented Interfaces :-
Serializable, ConcurrentMap<K,V>, Map<K,V>
Declaration of ConcurrentHashMap:
public class ConcurrentHashMap<K,V>
extends AbstractMap<K,V>
implements ConcurrentMap<K,V>, Serializable
ConcurrentHashMap is a implementation class of Map Interface.It belongs to java.util.*; package .
This class obeys the same functional specification as Hashtable, and implement all of the optional methods of the Map and Iterator interfaces.
All all operations of ConcurrentHashMap are thread-safe.
ConcurrentHashMap synchronizes or locks on certain portion of Map.To optimize the performance of ConcurrentHashMap ,Map is divided into different partitions depending upon the concurrency level.So that we do not need to synchronize the whole Map object.
This class does not allow null to be used as a key or value. This class is a member of the Java Collections Framework.
Constructor and Description :-
ConcurrentHashMap()
Creates a new, empty map with a default initial capacity (16), load factor (0.75) and concurrencyLevel (16).
ConcurrentHashMap(int initialCapacity)
Creates a new, empty map with the specified initial capacity, and with default load factor (0.75) and concurrencyLevel (16).
ConcurrentHashMap(int initialCapacity, float loadFactor)
Creates a new, empty map with the specified initial capacity and load factor and with the default concurrencyLevel (16).
ConcurrentHashMap(int initialCapacity, float loadFactor, int concurrencyLevel)
Creates a new, empty map with the specified initial capacity, load factor and concurrency level.
ConcurrentHashMap(Map<? extends K,? extends V> m)
Creates a new map with the same mappings as the given map.

No comments:
Post a Comment