{"id":134965,"date":"2020-07-21T08:28:51","date_gmt":"2020-07-21T00:28:51","guid":{"rendered":"http:\/\/4563.org\/?p=134965"},"modified":"2020-07-21T08:28:51","modified_gmt":"2020-07-21T00:28:51","slug":"concurrenthashmap-%e6%9e%84%e9%80%a0%e5%99%a8%e4%b8%ba%e5%95%a5%e8%a6%81%e8%bf%99%e4%b9%88%e5%a4%84%e7%90%86%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=134965","title":{"rendered":"ConcurrentHashMap \u6784\u9020\u5668\u4e3a\u5565\u8981\u8fd9\u4e48\u5904\u7406\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  ConcurrentHashMap \u6784\u9020\u5668\u4e3a\u5565\u8981\u8fd9\u4e48\u5904\u7406\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : amiwrong123 <\/span>  <span><i><\/i> 7<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<pre><code>    public ConcurrentHashMap(int initialCapacity) {         if (initialCapacity &lt; 0)             throw new IllegalArgumentException();         int cap = ((initialCapacity &gt;= (MAXIMUM_CAPACITY &gt;&gt;&gt; 1)) ?                    MAXIMUM_CAPACITY :                    tableSizeFor(initialCapacity + (initialCapacity &gt;&gt;&gt; 1) + 1));         this.sizeCtl = cap;     } <\/code><\/pre>\n<p>tableSizeFor \u7684\u9053\u7406\u6211\u90fd\u61c2\uff0c\u8fd9\u548c hashmap \u4e00\u6837\uff0c\u4f46\u8fd9\u91cc\u4e3a\u5565\u4e0d\u662f\u76f4\u63a5\u4f20\u9012 initialCapacity \u7ed9 tableSizeFor \u5462\uff1f<\/p>\n<p>\u6211\u628a\u4e24\u79cd\u60c5\u51b5\u5bf9\u6bd4\u4e86\u4e00\u4e0b\uff0c\u53d1\u73b0\u597d\u50cf\u4e5f\u6ca1\u5565\u89c4\u5f8b\u554a\uff1f<\/p>\n<pre><code>1 ==&gt; 1   1 ==&gt; 2 ==&gt; 2 2 ==&gt; 2   2 ==&gt; 4 ==&gt; 4 3 ==&gt; 4   3 ==&gt; 5 ==&gt; 8 4 ==&gt; 4   4 ==&gt; 7 ==&gt; 8 5 ==&gt; 8   5 ==&gt; 8 ==&gt; 8 6 ==&gt; 8   6 ==&gt; 10 ==&gt; 16 7 ==&gt; 8   7 ==&gt; 11 ==&gt; 16 8 ==&gt; 8   8 ==&gt; 13 ==&gt; 16 9 ==&gt; 16   9 ==&gt; 14 ==&gt; 16 10 ==&gt; 16   10 ==&gt; 16 ==&gt; 16 11 ==&gt; 16   11 ==&gt; 17 ==&gt; 32 12 ==&gt; 16   12 ==&gt; 19 ==&gt; 32 13 ==&gt; 16   13 ==&gt; 20 ==&gt; 32 14 ==&gt; 16   14 ==&gt; 22 ==&gt; 32 15 ==&gt; 16   15 ==&gt; 23 ==&gt; 32 16 ==&gt; 16   16 ==&gt; 25 ==&gt; 32 17 ==&gt; 32   17 ==&gt; 26 ==&gt; 32 18 ==&gt; 32   18 ==&gt; 28 ==&gt; 32 19 ==&gt; 32   19 ==&gt; 29 ==&gt; 32 20 ==&gt; 32   20 ==&gt; 31 ==&gt; 32 21 ==&gt; 32   21 ==&gt; 32 ==&gt; 32 22 ==&gt; 32   22 ==&gt; 34 ==&gt; 64 23 ==&gt; 32   23 ==&gt; 35 ==&gt; 64 24 ==&gt; 32   24 ==&gt; 37 ==&gt; 64 25 ==&gt; 32   25 ==&gt; 38 ==&gt; 64 26 ==&gt; 32   26 ==&gt; 40 ==&gt; 64 27 ==&gt; 32   27 ==&gt; 41 ==&gt; 64 28 ==&gt; 32   28 ==&gt; 43 ==&gt; 64 29 ==&gt; 32   29 ==&gt; 44 ==&gt; 64 30 ==&gt; 32   30 ==&gt; 46 ==&gt; 64 31 ==&gt; 32   31 ==&gt; 47 ==&gt; 64 32 ==&gt; 32   32 ==&gt; 49 ==&gt; 64 33 ==&gt; 64   33 ==&gt; 50 ==&gt; 64 34 ==&gt; 64   34 ==&gt; 52 ==&gt; 64 35 ==&gt; 64   35 ==&gt; 53 ==&gt; 64 36 ==&gt; 64   36 ==&gt; 55 ==&gt; 64 <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>9<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"2421240\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : luckyrayyy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u867d\u7136\u6211\u6ca1\u8bb0\u4f4f\u4f60\u7684 ID\uff0c\u4f46\u662f\u4e00\u770b\u95ee\u9898\u5c31\u6709\u9884\u611f\u662f\u8c01\u63d0\u95ee\u7684&#8230;.\u8001\u54e5\u52a0\u6cb9                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2421241\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sujin190 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5185\u5b58\u5bf9\u9f50\uff0c\u8fd8\u6709\u73b0\u5728\u5927\u90e8\u5206\u5185\u5b58\u5206\u914d\u7ba1\u7406\u5668\u90fd\u662f 2 \u7684\u500d\u6570\u5206\u914d\u7684\uff0c\u4e0d\u8fd9\u6837\u5904\u7406\u90a3\u5c31\u767d\u767d\u6d6a\u8d39\u5185\u5b58\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2421242\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : amiwrong123 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @luckyrayyy <br \/>\u662f\u56e0\u4e3a\u6211\u7ecf\u5e38\u53d1\u6e90\u7801\u8ba8\u8bba\u7684\u5e16\u5b50\u5417                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2421243\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : amiwrong123 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @sujin190 <br \/>\u53ef\u662f\u76f4\u63a5\u4f20\u9012 initialCapacity \u7ed9 tableSizeFor\uff0c\u7ed3\u679c\u4e5f\u662f 2 \u7684\u5e42\u554a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2421244\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : AmmeLid <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             2==&gt;2\uff0c\u4f9d\u7167\u4f60\u7684\u7b97\u6cd5\u8bbe\u7f6e\u5bb9\u91cf\u4e3a 2 \u7684\u8bdd\uff0c\u653e\u5165\u7b2c\u4e8c\u4e2a\u5143\u7d20\u7684\u65f6\u5019\u5c31\u8d85\u8fc7\u8d1f\u8f7d\u89e6\u53d1\u4e00\u6b21\u6269\u5bb9\u4e86\u5427                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2421245\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : amiwrong123 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @AmmeLid <br \/>\u597d\u5427\uff0c\u662f\u4f60\u8fd9\u4e2a\u610f\u601d\u3002\u6709\u70b9\u50cf\u662f\u9664\u4ee5 0.75 \u518d\u5411\u4e0a\u53d6\u6574\u7684\u611f\u89c9\uff0c\u4e0d\u5b8c\u5168\u548c \u9664\u4ee5 0.75 \u518d\u5411\u4e0a\u53d6\u6574 \u4e00\u6837                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2421246\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Hyseen <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u662f\u4e2a bug\uff0c\u5728 11 \u4e2d\u5df2\u7ecf\u4fee\u590d\u4e86<br \/>https:\/\/bugs.openjdk.java.net\/browse\/JDK-8202422                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2421247\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sujin190 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @amiwrong123 #4 \u4e0d\u662f 2 \u7684\u5e42\uff0c\u4f60\u53ef\u4ee5\u67e5\u4e00\u4e0b\u5927\u90e8\u5206\u5206\u914d\u5668\u7684\u5b9e\u73b0\uff0c\u5927\u90e8\u5206\u90fd\u662f 2 4 8 16 32 \u8fd9\u6837\u5206\u914d\u7684\uff0c\u500d\u6570\uff0c\u867d\u7136\u4f1a\u6d6a\u8d39\u4e00\u4e9b\u5185\u5b58\uff0c\u4f46\u662f\u5185\u5b58\u788e\u7247\u5c11\uff0c\u5206\u914d\u7ba1\u7406\u6548\u7387\u9ad8                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2421248\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : amiwrong123 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Hyseen <br \/>\u597d\u5427\uff0c\u539f\u6765\u5982\u6b64\u3002\u3002bug \u4fee\u6b63\u540e\uff0c\u6700\u8d77\u7801\u4e24\u79cd\u6784\u9020\u5668\u7ed3\u679c\u4e00\u6837\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>ConcurrentHashMap&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/134965"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=134965"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/134965\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=134965"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=134965"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=134965"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}