Concurrent Hashmap could solve synchronization issue which is seen in hashmap. So adding and removing would be fast if we are using synchronize key work with hashmap. What about checking hashmap size, if mulitple threads checking concurrentHashMap size? do we still need synchronzation key word: something as follows:
public static synchronized getSize(){
return aConcurrentHashmap.size();
}
concurentHashMap.size()will return the size known at the moment of the call, but it might be a stale value when you use that number because another thread has added / removed items in the meantime.However the whole purpose of ConcurrentMaps is that you don’t need to synchronize it as it is a thread safe collection.