HashMap & ConcurrentHashMap Implementation




 
 
 
ConcurrentHashMap
 
ConcurrentHashMap is the Threadsafe.

Default size is 16.
It is Bucket level lock for read /update. N thread can access for read operations.
But  only 16 threads can perform the update or write operation in Concurrent HashMap. 
Each bucket has one lock is Bucket/Segment Lock. Hence It increase the performance.
 
concurrency Level -> Total map divide into n number of blocks.
Concurrency level need not be the same as bucket size.
 
For example: Bucket size is 16 but concurrency level is 8 only. Then each two bucket have one lock.
 
 
ConcurrentHashMap map = new ConcurrentHashMap(int intialcapacity, int loadfactor, int concurrentLevel);
 
Methods
map.put(101,”A”);
map.putIfAbsent(103,”c”);
map.remove(101,”d”);
map.replace(101, “B”, “E”);
 

Comments

Popular posts from this blog

Robotic Process Automation

WorkFusion

7 Rules of Success A.P.J Abdul Kalam