Java Concurrenthashmap Initial knowledge

Source: Internet
Author: User

"Concurrenthashmap is a thread-safe hash table", but the key and value are not allowed to be empty;

Hashtable and Concurrenthashmap are thread-safe, but Hashtable is a synchronization container, Concurrenthashmap is a concurrent container, using the lock separation strategy, in the concurrency environment, should make more

With Concurrenthashmap, it has very good concurrency and can be read and written by multiple threads at the same time. Hashtable can only read and write to one thread at a time.

Concurrenthashmap can be simply understood as multiple hashmap combinations, and the lock is not on Concurrenthashmap, but on some hashmap. (segment mechanism)

As can be seen from the Concurrenthashmap code, it introduces a concept of "segmented lock", which can be understood as splitting a large map into N small hashtable (segment), according to the Key.hashcode () To decide which Hashtable to put the key in.

In Concurrenthashmap, it is the time to divide the map into n segment,put and get, which is now calculated based on Key.hashcode () to which segment:

Learn from: http://blog.csdn.net/xuefeng0707/article/details/40834595

Java Concurrenthashmap Initial knowledge

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.