In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "the principles and differences of HashMap, Hashtable and ConcurrentHashMap in java". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Let's first compare Hashtable with HashMap:
The biggest difference between Hashtable and HashMap is that they are thread-safe from Hashtable, while HashMap is not thread-safe. Hashtable is a key-value mapping data structure provided at the beginning of java release, while HashMap is generated by JDK1.2. Now that Hashtable has basically lost its common use, the first reason may be due to slow efficiency, but a large part of it is estimated to be due to failure to follow hump naming. To tell you the truth, my obsessive-compulsive disorder is very uncomfortable when I look at him! There are some other differences is that their parent class is also different, HashMap inherits from the AbstractMap class, and Hashtable inherits from the Dictionary class, and Hashtable neither key nor value can be null, thread safety is achieved by locking the entire Hashtable, which is extremely inefficient. Sure enough, there must be something undesirable in things that no one uses.
Let's take a look at ConcurrentHashMap:
The difference between hashMap and ConcurrentHashMap is actually similar to that between hashtable and hashMap. ConcurrentHashMap is also thread safe, but hashtable uses the synchronized keyword, while ConcurrentHashMap uses segmented locking technology, which combines the advantages of hashMap and synchronized. ConcurrentHashMap divides the hash table into 16 intervals by default, and normal operation only needs to use the current interval, so it seems that only one thread can enter, but now 16 threads can enter at the same time. The read thread is almost unaffected, and the write is locked, and the performance improvement is simply not the same.
This is the end of the introduction to the principles and differences of HashMap, Hashtable and ConcurrentHashMap in java. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.