{"id":94357,"date":"2020-05-02T04:30:57","date_gmt":"2020-05-01T20:30:57","guid":{"rendered":"http:\/\/4563.org\/?p=94357"},"modified":"2020-05-02T04:30:57","modified_gmt":"2020-05-01T20:30:57","slug":"threadlocalmap-%e7%9a%84%e6%ba%90%e7%a0%81%e7%9c%8b%e8%b5%b7%e6%9d%a5%e4%bc%9a%e8%80%83%e8%99%91%e4%b8%80%e7%a7%8d%e5%93%88%e5%b8%8c%e5%86%b2%e7%aa%81%e7%9a%84%e6%83%85%e5%86%b5%ef%bc%8c%e4%bd%86","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=94357","title":{"rendered":"ThreadLocalMap \u7684\u6e90\u7801\u770b\u8d77\u6765\u4f1a\u8003\u8651\u4e00\u79cd\u54c8\u5e0c\u51b2\u7a81\u7684\u60c5\u51b5\uff0c\u4f46\u4e0d\u662f ThreadLocal \u672c\u8eab\u5b9e\u73b0\u4e86\u5b8c\u7f8e\u6563\u5217\u5417\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  ThreadLocalMap \u7684\u6e90\u7801\u770b\u8d77\u6765\u4f1a\u8003\u8651\u4e00\u79cd\u54c8\u5e0c\u51b2\u7a81\u7684\u60c5\u51b5\uff0c\u4f46\u4e0d\u662f ThreadLocal \u672c\u8eab\u5b9e\u73b0\u4e86\u5b8c\u7f8e\u6563\u5217\u5417\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : amiwrong123 <\/span>  <span><i><\/i> 13<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u770b ThreadLocal \u7684\u6e90\u7801\uff0c\u5b83\u5229\u7528\u9b54\u6570<code>0x61c88647<\/code>\u5728 2 \u7684\u5e42\u4e3a\u5bb9\u91cf\u7684\u54c8\u5e0c\u8868\u4e0a\uff0c\u80fd\u591f\u5b8c\u7f8e\u6563\u5217\uff0c\u6ca1\u6709\u4e00\u4e2a\u5143\u7d20\u4f1a\u54c8\u5e0c\u51b2\u7a81\u3002<\/p>\n<pre><code>    private final int threadLocalHashCode = nextHashCode();      private static AtomicInteger nextHashCode =         new AtomicInteger();      private static final int HASH_INCREMENT = 0x61c88647;      private static int nextHashCode() {         return nextHashCode.getAndAdd(HASH_INCREMENT);     } <\/code><\/pre>\n<p>\u800c\u4e14\u6784\u9020\u6bcf\u4e2a ThreadLocal \u65f6\uff0c\u4f7f\u7528\u4e86 AtomicInteger \u6765\u5f97\u5230\u81ea\u5df1\u7684\u54c8\u5e0c\u503c\uff0c\u90a3\u4e48\u5c31\u7b97\u4e24\u4e2a\u7ebf\u7a0b\u540c\u65f6\u6784\u9020 ThreadLocal\uff0c\u4e24\u4e2a ThreadLocal \u5bf9\u8c61\u7684\u54c8\u5e0c\u503c\u4e5f\u662f\u4e0d\u540c\u7684\uff08\u8fd9\u4e48\u7406\u89e3\uff0c\u5bf9\u5427\uff1f\uff09\u3002<\/p>\n<p>\u7efc\u4e0a\uff0c\u4e24\u4e2a ThreadLocal \u5bf9\u8c61\u5728 ThreadLocalMap \u4e0d\u53ef\u80fd\u54c8\u5e0c\u51b2\u7a81\u3002<\/p>\n<p>\u800c\u4f60\u770b\u4e0b\u9762\u8fd9\u6bb5\u6e90\u7801\uff0c\u770b\u8d77\u6765\u4f1a\u8003\u8651\u4e00\u79cd\u54c8\u5e0c\u51b2\u7a81\u7684\u60c5\u51b5\uff0c\u4f46\u4e0d\u662f ThreadLocal \u672c\u8eab\u5b9e\u73b0\u4e86\u5b8c\u7f8e\u6563\u5217\u5417\uff1f\uff1a<\/p>\n<pre><code>        private Entry getEntry(ThreadLocal&lt;?&gt; key) {             int i = key.threadLocalHashCode &amp; (table.length - 1);             Entry e = table[i];  \/\/\u6839\u636e\u4e0b\u6807\u83b7\u5f97\u7684 entry \u53ef\u80fd\u4e3a null             \/\/\u53ea\u6709\u5f53 entry \u975e null\uff0c\u4e14 key \u4e3a\u540c\u4e00\u4e2a\u5bf9\u8c61\u65f6\uff0c\u624d\u76f4\u63a5\u8fd4\u56de value             if (e != null &amp;&amp; e.get() == key)                 return e;             \/\/\u5426\u5219 getEntryAfterMiss             else                 return getEntryAfterMiss(key, i, e);         }          \/**          * Version of getEntry method for use when key is not found in          * its direct hash slot.          *          * @param  key the thread local object          * @param  i the table index for key's hash code          * @param  e the entry at table[i]          * @return           *\/         private Entry getEntryAfterMiss(ThreadLocal&lt;?&gt; key, int i, Entry e) {             Entry[] tab = table;             int len = tab.length;              while (e != null) {                 ThreadLocal&lt;?&gt; k = e.get();                 if (k == key)                     return e;                 if (k == null)\/\/\u5bfb\u5740\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4e0d\u5de7\u53d1\u73b0\u4e86\u5305\u542b null key \u7684 entry                     expungeStaleEntry(i);                 else\/\/\u5229\u7528 nextIndex\uff0c\u5bfb\u5740\u5230\u51b2\u7a81\u540e\u7684\u5b9e\u9645\u4f4d\u7f6e                     i = nextIndex(i, len);                 e = tab[i];             }             return null;         } <\/code><\/pre>\n<p>\u6216\u8005\u8bf4\uff0c\u6211\u8ba4\u4e3a getEntryAfterMiss \u91cc\u9762\u7684<code>return e;<\/code>\u4e0d\u53ef\u80fd\u88ab\u8c03\u7528\u5230\uff0c\u56e0\u4e3a\u8fd9\u79cd\u60c5\u51b5\u53d1\u751f\uff0c\u5c31\u8bf4\u660e\u4e24\u4e2a ThreadLocal \u5bf9\u8c61\u7684\u54c8\u5e0c\u503c\u4e00\u6837\u4e86\uff0c\u4ea7\u751f\u4e86\u54c8\u5e0c\u51b2\u7a81\u3002<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>26<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"1204955\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lyjr <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u54c8\u5e0c\u503c\u4e0d\u540c\uff0c\u4f46\u662f\u8fd0\u7b97\u5f97\u5230\u7684\u5730\u5740\u662f\u53ef\u80fd\u76f8\u540c\u7684\uff0c\u5c31\u662f\u8fd9\u53e5\u55bd\uff0cint i = key.threadLocalHashCode &amp; (table.length &#8211; 1);<br \/>i \u80af\u5b9a\u53ef\u80fd\u51b2\u7a81\u561b\u3002<br \/>\u9ad8\u5c42\u9762\u4e0a\u60f3\u4e00\u60f3\u4e5f\u4e0d\u53ef\u80fd\u561b\uff0c\u4e16\u754c\u4e0a\u54ea\u6709\u4e0d\u51b2\u7a81\u7684\u54c8\u5e0c\u8868\uff0c\u4e00\u4e2a\u65e0\u9650\u7684\u96c6\u5408\u6620\u5c04\u5230\u4e00\u4e2a\u6709\u9650\u7684\u96c6\u5408\uff0c\u80fd\u4e0d\u51b2\u7a81\u5417                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1204956\" 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>                                                             @lyjr <br \/>\u4f46\u662f\u89c1\u6b64\u535a\u5ba2 https:\/\/www.cnblogs.com\/dennyzhangdd\/p\/7978455.html \u4e2d\u7684 MagicHashCode \u6d4b\u8bd5\u7c7b\uff0c\u5229\u7528\u9b54\u6570\u540e\uff0c\u5c31\u7b97\u662f\u53d6\u6a21\u540e\u7684 i\uff0c\u5728\u6709\u9650\u7684 2 \u7684\u5e42\u7684\u54c8\u5e0c\u8868\uff0c\u4e5f\u6ca1\u6709\u4e00\u4e2a i \u51b2\u7a81\u554a\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1204957\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wysnylc <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6709\u7b54\u6848\u4e86 @\u6211\u4e0b\u87f9\u87f9                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1204958\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lyjr <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @amiwrong123 \u4e3e\u4e2a\u6700\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u957f\u5ea6\u4e3a 2^3=8 \u7684\u54c8\u5e0c\u8868\uff0c\u63d2\u5165 9 \u4e2a\u5143\u7d20\uff0c\u5982\u679c\u4e0d\u51b2\u7a81\u7684\u8bdd\uff0c\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u653e\u5728\u54ea\u91cc\uff1f<br \/>\u6839\u672c\u4e0d\u7528\u60f3\u592a\u591a\uff0c\u8ddf\u4efb\u4f55\u6570\u636e\u7ed3\u6784\u548c\u7b97\u6cd5\u90fd\u65e0\u5173\uff0c\u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u96c6\u5408\u6620\u5c04\u7684\u6570\u5b66\u95ee\u9898\uff0c9 \u4e2a\u5143\u7d20\u7684\u96c6\u5408\u4e0d\u80af\u80fd\u65e0\u51b2\u7a81\u7684\u6620\u5c04\u5230\u5927\u5c0f\u4e3a 8 \u7684\u96c6\u5408\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1204959\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : coer <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u4e2a\u9b54\u6570\u53ef\u4ee5\u5b8c\u7f8e\u6563\u5217\uff0c\u5b66\u5230\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1204960\" 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>                                                             @lyjr <br \/>\u4f46\u662f\uff0cThreadLocalMap \u91cc\u9762\u7684 key\uff0c\u5982\u679c\u4e2a\u6570\u5927\u4e8e\u4e86\u9608\u503c\uff0c\u5c31\u4f1a\u5728 rehash \u554a\uff0c\u7136\u540e\u5bb9\u91cf\u53d8\u6210\u4e0b\u4e00\u4e2a 2 \u7684\u5e42\u3002\u4e5f\u5c31\u4e0d\u4f1a\u51fa\u73b0\u4f60\u8bf4\u7684\u8fd9\u79cd\u60c5\u51b5\u4e86\u554a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1204961\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : coer <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             https:\/\/blog.csdn.net\/outsanding\/article\/details\/104688125                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1204962\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : cheng6563 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6563\u5217\u90fd\u662f\u6709\u53ef\u80fd\u51b2\u7a81\u7684\uff0c\u4e0d\u7ba1\u591a\u5c11\u4f4d\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1204963\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wysnylc <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6590\u6ce2\u90a3\u5951\u6570\u5217,0x61c88647 \u5bf9\u5e94 10 \u8fdb\u5236\u662f 1640531527                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1204964\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : CoderGeek <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6709\u9650\u96c6\u6620\u5c04\u65e0\u9650 \u4f60\u544a\u8bc9\u6211\u6ca1\u51b2\u7a81 \u4f60\u7684\u6570\u636e\u7ed3\u6784\u8001\u5e08\u8981\u6253\u4eba\u4e86 \u79bb\u6563\u7684\u8001\u5e08\u4e5f\u8981\u6c14\u75af\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1204965\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lance6716 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @amiwrong123 \u5565\u73a9\u610f\uff0c0x61c88647 \u548b\u5c31\u6210\u4e86\u5b8c\u7f8e\u6563\u5217\u4e86\u3002csdn \u73b0\u5728\u8d8a\u6765\u8d8a\u80fd\u626f\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1204966\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : daozhihun <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u9b54\u6570\u53ea\u662f\u8ba9\u54c8\u5e0c\u76f8\u5bf9\u5747\u5300\u7684\u5206\u5e03\uff0c\u600e\u4e48\u53ef\u80fd\u5b8c\u5168\u6ca1\u6709\u51b2\u7a81\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1204967\" 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>                                                             \u597d\u5427\uff0c\u6211\u9519\u4e86\u3002\u6211\u597d\u50cf\u60f3\u901a\u4e86\u3002<br \/>&#8220;`java<br \/>import java.util.HashSet;<br \/>import java.util.Set;<\/p>\n<p>public class MagicHashCode {<br \/> private static final int HASH_INCREMENT = 0x61c88647;<\/p>\n<p> public static void main(String[] args) {<br \/> hashCode1();<br \/> }<\/p>\n<p> private static void hashCode1(){<br \/> Integer length = 32;<br \/> int hashCode = 0;<br \/> for(int i=0;i&lt;length;i++){<br \/> hashCode = i*HASH_INCREMENT;\/\/\u6bcf\u6b21\u9012\u589e HASH_INCREMENT<br \/> System.out.print((hashCode &amp; (16-1)) + &#8221; &#8220;);\/\/\u6c42\u6563\u5217\u4e0b\u6807\uff0c\u7b97\u6cd5\u516c\u5f0f<br \/> }<br \/> }<\/p>\n<p>}<br \/>&#8220;`<br \/>\u6253\u5370\u7ed3\u679c\uff1a0 7 14 5 12 3 10 1 8 15 6 13 4 11 2 9 0 7 14 5 12 3 10 1 8 15 6 13 4 11 2 9 <br \/>\u7ed3\u8bba\uff1a\u5148\u521b\u5efa 32 \u4e2a ThreadLocal\uff0c\u7136\u540e\u7ed9\u7ebf\u7a0b A \u5148\u8bbe\u7f6e\u7b2c 1 \u4e2a ThreadLocal\uff0c\u518d\u8bbe\u7f6e\u7b2c 17 \u4e2a ThreadLocal\uff0c\u7136\u540e\u5c31\u51b2\u7a81\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1204968\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lance6716 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @amiwrong123 0..15 \u653e 16 \u4e2a\u69fd\u4e92\u4e0d\u51b2\u7a81\u5f88\u7b80\u5355\uff0ckey = i \u5c31\u597d\u4e86\u554a\uff0c\u90fd\u6ca1\u90a3\u4e2a\u9b54\u6570\u4ec0\u4e48\u4e8b\u3002hash \u662f\u8981\u89e3\u51b3\u4e0d\u5b9a\u8303\u56f4\u7684\u6570\u653e 16 \u4e2a\u69fd                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1204969\" 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>                                                             @lance6716 #14<br \/>\u4f60\u8fd9\u4e48\u8bf4\uff0c\u5012\u771f\u662f\u54c8\u3002\u3002\u3002\u6bd4\u5982\u8ba9 ThreadLocal \u7684\u90a3\u4e2a\u9759\u6001\u53d8\u91cf HASH_INCREMENT \u4e3a 1 \u3002\u4e00\u6837\u5b9e\u73b0\uff0c2 \u7684\u5e42\u91cc\u5b8c\u7f8e\u6563\u5217\u7684\u6548\u679c\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1204970\" 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>                                                             @daozhihun <br \/>\u55ef\uff0c\u6211\u73b0\u5728\u7406\u89e3\u5230\u4e86\u8fd9\u70b9\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1204971\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Aresxue <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5b8c\u7f8e\u6563\u5217\u662f\u6307 hashCode \u4e0d\u51b2\u7a81\uff0c\u4f46\u662f\u6876\u4f4d\u7684\u8ba1\u7b97\u4e00\u822c\u90fd\u662f\u53d6\u540e\u51e0\u4f4d\u90a3\u4e48\u5c31\u5f88\u6709\u53ef\u80fd\u51b2\u7a81\uff0c\u8bf4\u5230\u5e95\u4f60\u6df7\u6dc6\u4e86\u6876\u4f4d\u548c hashCode                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1204972\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : daozhihun <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Aresxue hash code \u4e5f\u4e0d\u53ef\u80fd\u4e0d\u51b2\u7a81\uff0c32 \u4f4d\u7684 hash code \u4e0d\u53ef\u80fd\u53ef\u4ee5\u8868\u793a\u7406\u8bba\u4e0a\u65e0\u7a77\u591a\u7684\u5bf9\u8c61                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1204973\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jorneyr <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             import java.util.ArrayList;<br \/>import java.util.Collections;<br \/>import java.util.List;<\/p>\n<p>public class Test {<br \/> public static void main(String[] args) {<br \/> final int MAGIC_NUMBER = 0x61c88647;<br \/> final int N = 16;<\/p>\n<p> List&lt;Integer&gt; list = new ArrayList&lt;&gt;(N);<\/p>\n<p> for (int i = 0; i &lt; N; ++i) {<br \/> int index = (MAGIC_NUMBER * i) &amp; (N &#8211; 1);<br \/> list.add(index);<br \/> }<\/p>\n<p> System.out.println(list);<br \/> Collections.sort(list);<br \/> System.out.println(list);<\/p>\n<p> \/\/ \u5982\u679c\u975e\u9012\u589e\u5e8f\u5217\uff0c\u5219\u8f93\u51fa Error<br \/> for (int i = 1; i &lt; list.size(); ++i) {<br \/> if (list.get(i) &lt;= list.get(i-1)) {<br \/> System.out.println(&#8220;Error&#8221;);<br \/> break;<br \/> }<br \/> }<br \/> }<br \/>}<\/p>\n<p>\u8f93\u51fa<br \/>[0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9]<br \/>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]<\/p>\n<p>\u662f\u4e0d\u4f1a\u51b2\u7a81\u7684\uff0c\u5f53\u4f7f\u7528\u5230 80% \u7684\u65f6\u5019\u5c31\u6269\u5927\u6570\u7ec4\u4e86\uff0c\u6839\u672c\u4e0d\u7ed9\u4f7f\u7528\u5b8c\u7684\u673a\u4f1a\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1204974\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Aresxue <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @daozhihun \u8fd9\u53ea\u662f\u4e2a\u8fd1\u4f3c\u8bf4\u6cd5\uff0c\u56e0\u4e3a\u6b63\u5e38\u60c5\u51b5\u4e0b\u4f7f\u7528\u4e0d\u5230\u4e0a\u9650\u800c\u5df2\u3002\u800c\u4e0a\u9762\u7684\u5b8c\u7f8e\u6563\u5217\u4e5f\u53ea\u662f\u5229\u7528\u9ec4\u91d1\u5206\u5272\u7387\u6765\u8fbe\u5230\u4e00\u79cd\u52c9\u5f3a\u7684\u4e0d\u51b2\u7a81\u800c\u5df2(\u4e5f\u6ca1\u6709\u771f\u5b9e\u8fbe\u5230)\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u7684\u597d\u5904\u53ea\u5728\u4e8e\u8ba1\u7b97 hash \u7684\u65b9\u6cd5\u6781\u5176\u7b80\u5355\u6240\u4ee5\u6027\u80fd\u4e5f\u975e\u5e38\u7684\u597d                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1204975\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : brucefu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u770b\u6765\u8fd8\u662f\u61d2\u4e86\uff0cdebug \u5c31\u80fd\u89e3\u51b3\u4e86\uff0c\u54c8                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1204976\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : daozhihun <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Aresxue \u662f\u7684\uff0c\u4f60\u8fd9\u4e2a\u8bf4\u6cd5\u6ca1\u9519\uff0c\u53ea\u662f\u7ecf\u8fc7\u5f88\u591a\u5b9e\u9a8c\u5f97\u5230\u7684\u4e00\u4e2a\u76f8\u5bf9\u5747\u5300\u7684\u5206\u5e03\u65b9\u6cd5                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1204977\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : brucefu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u611f\u89c9\u5728\u95ee XX \u4e0d\u662f\u6c38\u52a8\u673a\u5417\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1204978\" 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>                                                             @Aresxue <br \/>@daozhihun <br \/>@lance6716 <br \/>\u5404\u4f4d\u5927\u4f6c\uff0c\u53ef\u5426\u518d\u5e2e\u5fd9\u89e3\u7b54\u4e00\u4e2a\u95ee\u9898\u3002<br \/>\u5c31\u662f\u4f7f\u7528\u8fd9\u4e2a\u9b54\u6570\u53ea\u662f\u4e3a\u4e86\u54c8\u5e0c\u76f8\u5bf9\u5747\u5300\u7684\u5206\u5e03\uff0c\u90a3\u4e48\u5982\u679c\u4e0d\u4f7f\u7528\u8fd9\u4e2a\u9b54\u6570\uff0c\u76f4\u63a5\u8ba9\u9759\u6001\u53d8\u91cf HASH_INCREMENT \u4e3a 1\uff0c\u4f1a\u6709\u4ec0\u4e48\u574f\u5904\u5417\uff1f\uff08\u662f\u4e0d\u662f\u56e0\u4e3a ThreadLocalMap \u7528\u7684\u5f00\u53d1\u5bfb\u5740\uff0c\u6240\u4ee5\u5982\u679c\u54c8\u5e0c\u5747\u5300\u5206\u5e03\uff0c\u90a3\u4e48\u51b2\u7a81\u7684\u65f6\u5019\uff0c\u5c31\u80fd\u5927\u6982\u7387\u66f4\u5feb\u7684\u627e\u5230\u51b2\u7a81\u540e\u7684\u65b0\u4f4d\u7f6e\u5417\uff09                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1204979\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : daozhihun <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @amiwrong123 https:\/\/stackoverflow.com\/questions\/38994306\/what-is-the-meaning-of-0x61c88647-constant-in-threadlocal-java                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1204980\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lance6716 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @amiwrong123 \u7b49\u4e8e 1 \u7684\u8bdd\uff0c\u54c8\u5e0c\u7ed3\u679c\u5747\u5300\u8981\u4f9d\u8d56\u8f93\u5165\u5747\u5300\u3002\u73b0\u5728\u5bf9\u8f93\u5165\u7684\u4f9d\u9760\u66f4\u5f31                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>ThreadLocalMap \u7684\u6e90&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\/94357"}],"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=94357"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/94357\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=94357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=94357"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=94357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}