Difference between CocurrentHashMap and Hashtable, cocurrenthashmap
Collection classes are the core of Java APIs, but I think it is an art to make good use of them. I have summarized some personal experiences, such as using ArrayList to improve performance, rather than needing outdated vectors. JDK 1.5 introduces some easy-to-use concurrent collection classes, which are very useful for large e-commerce systems that require low latency. This article will look at the differences between ConcurrentHashMap and Hashtable.
This article describes how HashMap works and the differences between HashMap and Hashtable. If you have read this article, I believe you will gain some benefits after reading this article.
Why do we need ConcurrentHashMap and CopyOnWriteArrayList?
Synchronous collection class (Hashtable and Vector), synchronous encapsulation class (using Collections. synchronizedMap () method and Collections. the objects returned by the synchronizedList () method can be used to create a thread-safe Map and List. But some factors make them unsuitable for High-concurrency systems. They only have a single lock, lock the entire set, and often lock the set for a period of time during iteration to prevent ConcurrentModificationException. These features are all obstacles to scalability.
ConcurrentHashMap and CopyOnWriteArrayList keep thread security while providing higher concurrency. ConcurrentHashMap and CopyOnWriteArrayList are not used everywhere. In most cases, you only need HashMap and ArrayList to deal with common situations.
Difference between ConcurrentHashMap and Hashtable
What are the differences between Hashtable and ConcurrentHashMap? They can all be used in multi-threaded environments, but when the size of Hashtable increases to a certain extent, the performance will drop sharply, because the iteration needs to be locked for a long time. Because ConcurrentHashMap introduces segmentation, no matter how large it becomes, it only needs to lock a part of the map, and other threads do not need to wait until the iteration is complete to access map. In short, in the iteration process, ConcurrentHashMap only locks a part of the map, while Hashtable locks the entire map.
Article