{"id":39020,"date":"2023-12-11T14:46:11","date_gmt":"2023-12-11T06:46:11","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=39020"},"modified":"2023-12-11T14:46:11","modified_gmt":"2023-12-11T06:46:11","slug":"%e8%af%b7%e4%bd%a0%e8%af%b4%e6%98%8e%e4%b8%80%e4%b8%8bconcurrenthashmap%e7%9a%84%e5%8e%9f%e7%90%86%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/12\/11\/%e8%af%b7%e4%bd%a0%e8%af%b4%e6%98%8e%e4%b8%80%e4%b8%8bconcurrenthashmap%e7%9a%84%e5%8e%9f%e7%90%86%ef%bc%9f\/","title":{"rendered":"\u8bf7\u4f60\u8bf4\u660e\u4e00\u4e0bConcurrentHashMap\u7684\u539f\u7406\uff1f"},"content":{"rendered":"<p>&#8220;`&#8221;                    \u8003\u5bdf\u70b9\uff1aJAVA\u5185\u5b58\u6a21\u578b<\/p>\n<p>ConcurrentHashMap \u7c7b\u4e2d\u5305\u542b\u4e24\u4e2a\u9759\u6001\u5185\u90e8\u7c7b HashEntry \u548c Segment\u3002HashEntry \u7528\u6765\u5c01\u88c5\u6620\u5c04\u8868\u7684\u952e \/ \u503c\u5bf9\uff1bSegment \u7528\u6765\u5145\u5f53\u9501\u7684\u89d2\u8272\uff0c\u6bcf\u4e2a Segment \u5bf9\u8c61\u5b88\u62a4\u6574\u4e2a\u6563\u5217\u6620\u5c04\u8868\u7684\u82e5\u5e72\u4e2a\u6876\u3002\u6bcf\u4e2a\u6876\u662f\u7531\u82e5\u5e72\u4e2a HashEntry \u5bf9\u8c61\u94fe\u63a5\u8d77\u6765\u7684\u94fe\u8868\u3002\u4e00\u4e2a ConcurrentHashMap \u5b9e\u4f8b\u4e2d\u5305\u542b\u7531\u82e5\u5e72\u4e2a Segment \u5bf9\u8c61\u7ec4\u6210\u7684\u6570\u7ec4\u3002HashEntry \u7528\u6765\u5c01\u88c5\u6563\u5217\u6620\u5c04\u8868\u4e2d\u7684\u952e\u503c\u5bf9\u3002\u5728 HashEntry \u7c7b\u4e2d\uff0ckey\uff0chash \u548c next \u57df\u90fd\u88ab\u58f0\u660e\u4e3a final \u578b\uff0cvalue \u57df\u88ab\u58f0\u660e\u4e3a volatile \u578b\u3002&lt;\/p&gt;<\/p>\n<p>&lt;pre&gt;&lt;code&gt;static final class HashEntry {    final K key;             \/\/ \u58f0\u660e key \u4e3a final \u578b    final int hash;           \/\/ \u58f0\u660e hash \u503c\u4e3a final \u578b     volatile V value;          \/\/ \u58f0\u660e value \u4e3a volatile \u578b     final HashEntry next;     \/\/ \u58f0\u660e next \u4e3a final \u578b       HashEntry(K key, int hash, HashEntry next, V value) {     \t  this.key = key;    \t  this.hash = hash;  \t  this.next = next;   \t  this.value = value;    }}&lt;\/code&gt;&lt;\/pre&gt;<\/p>\n<p>\u5728ConcurrentHashMap \u4e2d\uff0c\u5728\u6563\u5217\u65f6\u5982\u679c\u4ea7\u751f\u201c\u78b0\u649e\u201d\uff0c\u5c06\u91c7\u7528\u201c\u5206\u79bb\u94fe\u63a5\u6cd5\u201d\u6765\u5904\u7406\u201c\u78b0\u649e\u201d\uff1a\u628a\u201c\u78b0\u649e\u201d\u7684 HashEntry \u5bf9\u8c61\u94fe\u63a5\u6210\u4e00\u4e2a\u94fe\u8868\u3002\u7531\u4e8e HashEntry \u7684 next \u57df\u4e3a final \u578b\uff0c\u6240\u4ee5\u65b0\u8282\u70b9\u53ea\u80fd\u5728\u94fe\u8868\u7684\u8868\u5934\u5904\u63d2\u5165\u3002 \u4e0b\u56fe\u662f\u5728\u4e00\u4e2a\u7a7a\u6876\u4e2d\u4f9d\u6b21\u63d2\u5165 A\uff0cB\uff0cC \u4e09\u4e2a HashEntry \u5bf9\u8c61\u540e\u7684\u7ed3\u6784\u56fe\uff1a<\/p>\n<p>\u56fe1. \u63d2\u5165\u4e09\u4e2a\u8282\u70b9\u540e\u6876\u7684\u7ed3\u6784\u793a\u610f\u56fe\uff1a<\/p>\n<p>\u00a0<\/p>\n<p>&lt;img alt=&quot;&quot;img&quot;&quot; referrerpolicy=&quot;&quot;no-referrer&quot;&quot; src=&quot;&quot;https:\/\/uploadfiles.nowcoder.com\/images\/20180925\/308572_1537878284540_B6C31D01D41C9E1714958F9C56D01D8F&quot;&quot;&gt;<\/p>\n<p>\u6ce8\u610f\uff1a\u7531\u4e8e\u53ea\u80fd\u5728\u8868\u5934\u63d2\u5165\uff0c\u6240\u4ee5\u94fe\u8868\u4e2d\u8282\u70b9\u7684\u987a\u5e8f\u548c\u63d2\u5165\u7684\u987a\u5e8f\u76f8\u53cd\u3002<\/p>\n<p>Segment \u7c7b\u7ee7\u627f\u4e8e ReentrantLock \u7c7b\uff0c\u4ece\u800c\u4f7f\u5f97 Segment \u5bf9\u8c61\u80fd\u5145\u5f53\u9501\u7684\u89d2\u8272\u3002\u6bcf\u4e2a Segment \u5bf9\u8c61\u7528\u6765\u5b88\u62a4\u5176\uff08\u6210\u5458\u5bf9\u8c61 table \u4e2d\uff09\u5305\u542b\u7684\u82e5\u5e72\u4e2a\u6876\u3002<\/p>\n<p>&lt;pre&gt;&lt;code&gt;            &quot;&#8220;`<br \/>\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;`&#8221; \u8003\u5bdf\u70b9\uff1aJAVA\u5185\u5b58\u6a21\u578b ConcurrentHashMap \u7c7b\u4e2d\u5305\u542b\u4e24\u4e2a\u9759\u6001 [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-39020","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/39020","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=39020"}],"version-history":[{"count":1,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/39020\/revisions"}],"predecessor-version":[{"id":39021,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/39020\/revisions\/39021"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=39020"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=39020"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=39020"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}