久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

ConcurrentHashMap的Segment和HashMap的bucket在理論上有什

What is the difference between Segment of ConcurrentHashMap and buckets of HashMap theoretically?(ConcurrentHashMap的Segment和HashMap的bucket在理論上有什么區(qū)別?)
本文介紹了ConcurrentHashMap的Segment和HashMap的bucket在理論上有什么區(qū)別?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我了解在HashMap中,條目(Key,Value)是根據(jù)hash(Key.hashCode)放在桶中的-->表示桶位置的索引.如果條目已經(jīng)放置在該位置,則會創(chuàng)建一個鏈表,并且新條目(如果它具有不同的鍵 --> 通過 equals() 方法)放置在鏈表的開頭.

I understand that in HashMap, the entries (Key, Value) are placed in buckets based on hash(Key.hashCode)--> The index that denotes the bucket location. In case an entry is already placed at that location, there is a linked list created and the new entry (if it has different key --> via equals() method) is placed at the beginning of the linked list.

  1. 我能否將這個概念與 ConcurrentHashMap 的概念相關(guān)聯(lián),但不是 Buckets,而是有各個線程在其上具有鎖的 Segment.而不是 Entries,有 HashEntry(ies).以類似的方式創(chuàng)建一個鏈表,如果插入的鍵值對不同,則根據(jù)鍵的 equals() 將其放在鏈表的末尾.
  2. 我這樣說對嗎:CHM 的 put 是不同步的,因此任何線程都可以訪問這個方法,這個 put 方法計算傳遞給它的鍵的哈希值并獲取段索引(有點像桶).然后僅針對該段,它調(diào)用 put 方法.現(xiàn)在在 Segment 下, put 方法指定將有一個 lock(),因此只有一個線程可以更改特定段中的數(shù)據(jù),因此得出結(jié)論,如果并發(fā)級別為 16,則應(yīng)有 16 個線程,因此這些線程將是一次只能PUT值一個段.

推薦答案

  1. 桶是地圖數(shù)組中的一個單獨的槽.這對于 HashMapConcurrentHashMap 都是一樣的.從概念上講,后者將其數(shù)組分解為段(每個段都是引用數(shù)組),僅此而已.請注意,Java 8 中的 CHM 不再有段,而是一個數(shù)組.

  1. A bucket is an individual slot in the map's array. This is the same with both HashMap and ConcurrentHashMap. Conceptually, the latter has its array broken into segments (each segment is an array of references), but that's it. Note that the CHM in Java 8 no longer has segments, it's all a single array.

是的,這就是稱為分段鎖定的方案.它減少了線程間爭用,但并沒有消除它.

Yes, it's the scheme known as segmented locking. It reduces inter-thread contention, but does not eliminate it.

這篇關(guān)于ConcurrentHashMap的Segment和HashMap的bucket在理論上有什么區(qū)別?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Convert List of Strings into Map using Java-8 Streams API(使用 Java-8 Streams API 將字符串列表轉(zhuǎn)換為 Map)
Getting data from JSON(從 JSON 獲取數(shù)據(jù))
java linkedhashmap iteration(javalinkedhashmap迭代)
Converting a list of objects to Map(將對象列表轉(zhuǎn)換為 Map)
Create a HashMap with a fixed Key corresponding to a HashSet. point of departure(用一個固定的Key對應(yīng)一個HashSet創(chuàng)建一個HashMap.出發(fā)點)
HttpMessageConverter exception : RestClientException: Could not write request: no suitable HttpMessageConverter found(HttpMessageConverter 異常:RestClientException:無法寫入請求:找不到合適的 HttpMessageConverter) - IT屋-程序員
主站蜘蛛池模板: 欧美aa在线| 久久精品久久久久久 | 国产色婷婷精品综合在线播放 | 中文字幕日韩欧美一区二区三区 | 一级片成人 | www久久99 | 北条麻妃一区二区三区在线视频 | 一级毛片大全免费播放 | 午夜激情免费 | 久久久久国产精品人 | 欧美日韩一 | 欧美专区日韩 | 成人亚洲一区 | 日韩影院在线 | 自拍 亚洲 欧美 老师 丝袜 | 黄网站在线播放 | 亚洲在线成人 | 超碰婷婷 | 欧美男人天堂 | 精品国产黄a∨片高清在线 www.一级片 国产欧美日韩综合精品一区二区 | 欧美黄色大片在线观看 | 99久久99| 一区二区三区国产视频 | 亚洲视频免费在线观看 | 日本精品视频在线 | 久久久精品| 国产精品自拍视频 | 99久久国产综合精品麻豆 | 亚洲成av人片在线观看 | 午夜小电影 | 懂色av蜜桃av | 日韩电影免费在线观看中文字幕 | 91看片网| 欧美精品在线视频 | 国产一级成人 | 精品视频一区二区三区在线观看 | 欧美国产视频 | 激情一区二区三区 | 久久午夜国产精品www忘忧草 | 毛片黄| 91国内精品久久 |