{"id":10008039,"date":"2023-07-05T15:00:26","date_gmt":"2023-07-05T07:00:26","guid":{"rendered":"https:\/\/ityet.com\/?p=10008039"},"modified":"2023-07-05T15:00:26","modified_gmt":"2023-07-05T07:00:26","slug":"%e6%88%91%e5%9d%9a%e5%ae%9a%e7%9a%84%e8%ae%a4%e4%b8%ba%ef%bc%8c%e8%bf%99%e4%b8%aa%e6%ba%90%e7%a0%81%e8%82%af%e5%ae%9a%e6%98%af%e6%9c%89-bug-%e7%9a%84%ef%bc%81","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10008039","title":{"rendered":"\u6211\u575a\u5b9a\u7684\u8ba4\u4e3a\uff0c\u8fd9\u4e2a\u6e90\u7801\u80af\u5b9a\u662f\u6709 BUG \u7684\uff01"},"content":{"rendered":"<p>\u4f60\u597d\u5440\uff0c\u6211\u662f\u6b6a\u6b6a\u3002<\/p>\n<p>\u4e0a\u5468\u6211\u4e0d\u662f\u53d1\u4e86<a href=\"https:\/\/link.segmentfault.com\/?enc=a%2FtUA%2B7kTZswiRigosiTMQ%3D%3D.YdY%2BMj11Q7Ua7iMyzLMHmpSw8%2BlJC%2B0Nv2LksR5Y%2BuWVL3NOAj69VNtnVRjZiWvhj3gP1EVjysQ058ag1xlyRg%3D%3D\" rel=\"nofollow\">\u300a\u6211\u8bd5\u56fe\u7ed9\u4f60\u5206\u4eab\u4e00\u79cd\u81ea\u9002\u5e94\u7684\u8d1f\u8f7d\u5747\u8861\u3002\u300b<\/a>\u8fd9\u7bc7\u6587\u7ae0\u561b\uff0c\u91cc\u9762\u4e00\u79cd\u53eb\u505a\u201c\u81ea\u9002\u5e94\u8d1f\u8f7d\u5747\u8861\u201d\u7684\u8d1f\u8f7d\u5747\u8861\u7b56\u7565\uff0c\u6838\u5fc3\u601d\u8def\u5c31\u662f\u4ece\u591a\u4e2a\u670d\u52a1\u63d0\u4f9b\u8005\u4e2d\u968f\u673a\u9009\u62e9\u4e24\u4e2a\u51fa\u6765\uff0c\u7136\u540e\u7ee7\u7eed\u9009\u62e9\u4e24\u8005\u4e2d\u201c\u8d1f\u8f7d\u201d\u6700\u5c0f\u7684\u90a3\u4e2a\u8282\u70b9\u3002<\/p>\n<p>\u524d\u51e0\u5929\u6709\u8bfb\u8005\u770b\u4e86\u6587\u7ae0\u540e\u627e\u5230\u6211\uff0c\u63d0\u51fa\u4e86\u4e24\u4e2a\u95ee\u9898\u3002<\/p>\n<p>\u6709\u70b9\u610f\u601d\uff0c\u6211\u7ed9\u4f60\u76d8\u4e00\u4e0b\u3002<\/p>\n<h2>\u7b2c\u4e00\u4e2a\u95ee\u9898<\/h2>\n<p>\u7b2c\u4e00\u4e2a\u95ee\u9898\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043971740\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u4ed6\u7684\u56fe\u7247\uff0c\u6307\u7684\u662f\u6587\u7ae0\u4e2d\u7684\u8fd9\u4e2a\u90e8\u5206\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043971741\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u5f53\u65f6\u6211\u4e5f\u6ca1\u6709\u7ec6\u770b\uff0c\u6240\u4ee5\u6211\u7684\u56de\u590d\u662f timeout \u662f\u4e2a\u914d\u7f6e\u9879\uff0c\u6211\u8fd9\u91cc\u53d6\u51fa\u6765\u90fd\u662f 30000 \u7684\u539f\u56e0\u662f\u56e0\u4e3a\u6211\u6ca1\u6709\u8fdb\u884c\u914d\u7f6e\u3002<\/p>\n<p>\u7136\u540e\uff0c\u4ed6\u5bf9\u4e8e\u95ee\u9898\u8fdb\u884c\u4e86\u8fdb\u4e00\u6b65\u7684\u63cf\u8ff0\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043971742\" alt=\"\" title=\"\" loading=\"lazy\">.png)<\/p>\n<p>\u6211\u70b9\u5230\u6e90\u7801\u91cc\u9762\u4e00\u770b\uff0c\u597d\u5bb6\u4f19\uff0c\u5b83\u662f\u8fd9\u6837\u5199\u7684\uff1a<\/p>\n<pre><code>int timeout1 = getTimeout(invoker2, invocation);\nint timeout2 = getTimeout(invoker2, invocation);<\/code><\/pre>\n<p>\u4e24\u6b21\u8c03\u7528 getTimeout \u65b9\u6cd5\u7684\u5165\u53c2\u4e00\u6a21\u4e00\u6837\u3002\u8fd9\u4e2a\u5730\u65b9\u4f60\u7528\u811a\u6307\u5934\u60f3\u4e5f\u5e94\u8be5\u80fd\u77e5\u9053\u5b83\u7684\u53c2\u6570\u4f20\u9012\u9519\u8bef\u4e86\u561b\u3002<\/p>\n<p>\u6211\u751a\u81f3\u80fd\u731c\u5230\u4f5c\u8005\u5199\u8fd9\u4e00\u884c\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u6309\u4e86\u4e00\u4e2a ctrl+d \u5feb\u6377\u952e\uff0c\u590d\u5236\u4e86\u4e00\u884c\u51fa\u6765\uff0c\u7ed3\u679c\u53ea\u662f\u628a\u524d\u9762\u7684 timeout1 \u6539\u6210\u4e86 timeout2\uff0c\u5fd8\u8bb0\u6539\u540e\u9762\u4e86\u3002<\/p>\n<p>\u8fd9\u79cd\u4f4e\u7ea7\u9519\u8bef&#8230;<\/p>\n<p>\u6211\u4e5f\u72af\u8fc7\u597d\u51e0\u6b21\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043971743\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u7136\u540e\u6211\u53eb\u8fd9\u4e2a\u8bfb\u8005\u53ef\u4ee5\u53bb\u63d0\u4e00\u4e2a pr\uff0c\u4ee5\u540e\u51fa\u53bb\u5439\u725b\u7684\u65f6\u5019\u5c31\u53ef\u4ee5\u8bf4\uff1a\u6211\u66fe\u7ecf\u7ed9 apache \u9876\u7ea7\u5f00\u6e90\u9879\u76ee\u8d21\u732e\u8fc7\u6e90\u7801\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043971744\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u4f46\u662f\u8fd9\u4e2a\u8bfb\u8005\u53ef\u80fd\u6bd4\u8f83\u4f4e\u8c03\uff0c\u628a\u8fd9\u4e2a\u673a\u4f1a\u8ba9\u7ed9\u6211\u4e86\u3002<\/p>\n<p>\u4e8e\u662f&#8230;<\/p>\n<p>\u6211\u5c31\u539a\u7740\u8138\u76ae\u53bb\u63d0 pr \u4e86\uff0c\u7136\u540e\u88ab merge \u4e86\uff1a<\/p>\n<blockquote><p><a href=\"https:\/\/link.segmentfault.com\/?enc=tofl%2FVnt4Uxpz6dDy%2FmE4g%3D%3D.NPrbm%2B5mfVZc0c%2FfUIs8lDpKHZ%2B%2BUkUDmvI%2FPI%2FEGyLFvQ8yIa11cG0PGnwB%2FTWy\" rel=\"nofollow\">https:\/\/github.com\/apache\/dubbo\/pull\/12636<\/a><\/p><\/blockquote>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043971745\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u628a invoker2 \u4fee\u6539\u4e3a invoker1\uff0c\u641e\u5b9a\u3002<\/p>\n<p>\u8212\u670d\u4e86\uff0c\u5728\u6211\u56db\u5904\u6df7 pr \u7684\u5149\u8363\u4e8b\u8ff9\u4e2d\uff0c\u53c8\u6dfb\u52a0\u4e86\u6d53\u58a8\u91cd\u5f69\u7684\u4e00\u7b14\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043971746\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h2>\u7b2c\u4e8c\u4e2a\u95ee\u9898<\/h2>\n<p>\u7b2c\u4e8c\u4e2a\u95ee\u9898\uff0c\u5176\u5b9e\u6211\u5728\u4e4b\u524d\u7684\u6587\u4e2d\u4e5f\u63d0\u5230\u4e86\u3002<\/p>\n<p>\u6587\u7ae0\u91cc\u9762\u5bf9\u4e8e\u201c\u968f\u673a\u9009\u62e9\u4e24\u4e2a\u201d\u51fa\u6765\u8fd9\u4e2a\u52a8\u4f5c\u7684\u4ee3\u7801\u5b9e\u73b0\uff0c\u6211\u611f\u89c9\u662f\u6709 BUG \u7684\uff0c\u6240\u4ee5\u63d0\u51fa\u4e86\u4e00\u4e2a\u5927\u80c6\u7684\u8d28\u7591\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043971747\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u4f46\u662f\u79c9\u7740\u201c\u53c8\u4e0d\u662f\u4e0d\u80fd\u7528\u201d\u7684\u6838\u5fc3\u601d\u8def\uff0c\u5f53\u65f6\u4e5f\u6ca1\u6709\u7ec6\u60f3\u3002<\/p>\n<p>\u5f53\u6211\u524d\u9762\u7684\u90a3\u4e2a pr \u88ab merge \u7684\u65f6\u5019\uff0c\u6211\u51b3\u5b9a\uff1a\u8981\u4e0d\u597d\u4eba\u505a\u5230\u5e95\uff0c\u628a\u8fd9\u4e2a BUG \u4e5f\u5e2e\u5b83\u4eec\u4fee\u590d\u4e00\u4e0b\u5427\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u6765\u8be6\u7ec6\u89e3\u91ca\u4e00\u4e0b\uff0c\u6211\u4e3a\u4ec0\u4e48\u4f1a\u8ba4\u4e3a\u8fd9\u4e2a\u5730\u65b9\u6709 BUG\u3002<\/p>\n<p>\u9996\u5148\uff0c\u628a\u5b83\u7684\u6574\u4e2a\u6e90\u7801\u62ff\u8fc7\u6765\uff1a<\/p>\n<pre><code>int pos1 = ThreadLocalRandom.current().nextInt(length);\nint pos2 = ThreadLocalRandom.current().nextInt(length - 1);\nif (pos2 == pos1) {\n    pos2 = pos2 + 1;\n}<\/code><\/pre>\n<p>\u6211\u5c31\u4ee5\u6700\u7b80\u5355\u7684\u60c5\u51b5\uff0c\u53ea\u6709\u4e09\u4e2a\u670d\u52a1\u63d0\u4f9b\u8005\uff0c\u5373 length=3\uff0c\u7136\u540e\u968f\u673a\u9009\u4e24\u4e2a\u51fa\u6765\uff0c\u8fd9\u79cd\u60c5\u51b5\u6765\u8fdb\u884c\u8bf4\u660e\u3002<\/p>\n<p>\u6211\u4e5f\u4e0d\u8fdb\u884c\u6570\u5b66\u8bba\u8bc1\u4e86\uff0c\u76f4\u63a5\u5c31\u662f\u7ed9\u4f60\u8868\u6f14\u4e00\u4e2a\u7a77\u4e3e\u5927\u6cd5\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u7684 invokers \u96c6\u5408\u91cc\u9762\u6709\u4e09\u4e2a\u670d\u52a1\u63d0\u4f9b\u65b9\uff0cinvoker1\uff0cinvoker2\uff0cinvoker3\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043971748\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u5f53\u6267\u884c\u8fd9\u4e00\u884c\u4ee3\u7801\u7684\u65f6\u5019\uff1a<\/p>\n<blockquote><p>int pos1 = ThreadLocalRandom.current().nextInt(length);<\/p><\/blockquote>\n<p>length=3\uff0c\u5373<\/p>\n<blockquote><p>int pos1 = ThreadLocalRandom.current().nextInt(3);<\/p><\/blockquote>\n<p>\u6240\u4ee5 pos1 \u7684\u53d6\u503c\u8303\u56f4\u662f [0,3)\u3002<\/p>\n<p>\u524d\u9762\u8bf4\u4e86\uff0c\u6211\u8981\u7528\u7a77\u4e3e\u5927\u6cd5\uff0c\u6240\u4ee5\u6211\u4eec\u8981\u5206\u6790 pos1 \u5206\u522b\u4e3a 0,1,2 \u7684\u65f6\u5019\u3002<\/p>\n<h3>pos1=0<\/h3>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u5206\u6790 pos1=0 \u7684\u60c5\u51b5\u3002<\/p>\n<p>\u5f53 pos1=0 \u65f6\uff0c\u6211\u4eec\u8981\u7b97 pos2 \u7684\u503c\uff0c\u5f53\u6267\u884c\u8fd9\u884c\u4ee3\u7801\u7684\u65f6\u5019\uff1a<\/p>\n<blockquote><p>int pos2 = ThreadLocalRandom.current().nextInt(length &#8211; 1);<\/p><\/blockquote>\n<p>\u5b83\u7684\u53d6\u503c\u8303\u56f4\u662f [0,2)\u3002<\/p>\n<p>\u6240\u4ee5\uff0c\u7ecf\u8fc7\u4e24\u884c\u968f\u673a\u7684\u4ee3\u7801\u4e4b\u540e\uff0c\u6211\u4eec\u80fd\u5f97\u5230\u8fd9\u6837\u7684\u7ec4\u5408\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043971749\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u9488\u5bf9\u7ec4\u5408\u4e00\uff0c\u53c8\u56e0\u4e3a\u6709\u8fd9\u4e2a\u5224\u65ad\u5728\u8fd9\u91cc\uff1a<\/p>\n<pre><code>if (pos2 == pos1) {\n    pos2 = pos2 + 1;\n}<\/code><\/pre>\n<p>\u5f53 pos2 = pos1\uff0c\u5373\u968f\u673a\u5230\u540c\u4e00\u4e2a\u4e0b\u6807\u7684\u65f6\u5019\uff0cpos2 \u9700\u8981\u52a0\u4e00\uff0c\u4ee5\u514d\u4f7f\u7528\u540c\u4e00\u4e2a invoker\u3002<\/p>\n<p>\u6240\u4ee5\uff0c\u5f53 pos1=0 \u65f6\uff0c\u968f\u673a\u7684\u6700\u7ec8\u53ea\u4f1a\u662f\u8fd9\u4e24\u79cd\u60c5\u51b5\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043971750\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>pos1=1<\/h3>\n<p>\u540c\u7406\uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u51fa pos1=1 \u65f6\uff0c\u60c5\u51b5\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043971751\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>pos1=2<\/h3>\n<p>\u5f53 pos1=2 \u65f6\uff0c\u60c5\u51b5\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043971752\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>\u6c47\u603b<\/h3>\n<p>\u6b64\u65f6\uff0c\u6211\u4eec\u6240\u6709\u60c5\u51b5\u90fd\u5206\u6790\u5b8c\u6210\u4e86\uff0c\u7a77\u4e3e\u5927\u6cd5\u5df2\u7ecf\u4f7f\u7528\u5b8c\u6bd5\u3002<\/p>\n<p>\u8fd9\u4e2a\u65f6\u5019\u6211\u4eec\u628a\u6240\u6709\u7684\u60c5\u51b5\u7ec4\u5408\u8d77\u6765\u770b\u4e00\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043971753\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<ul>\n<li>invoker1 \u88ab\u9009\u4e2d\u4e86 4 \u6b21<\/li>\n<li>invoker2 \u88ab\u9009\u4e2d\u4e86 5 \u6b21<\/li>\n<li>invoker3 \u88ab\u9009\u4e2d\u4e86 3 \u6b21<\/li>\n<\/ul>\n<p>\u6765\uff0c\u8bf7\u4f60\u5927\u58f0\u70b9\u7684\u544a\u8bc9\u6211\uff0c\u8fd9\u4e2a\u7b97\u6cd5\u662f\u4e0d\u662f\u516c\u5e73\u7684\uff1f<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043971754\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u90fd\u4e0d\u662f 1:1:1 \u4e86\uff0c\u8fd8\u516c\u5e73\u4e2a\u5565\u554a\u3002<\/p>\n<p>\u6240\u4ee5\uff0c\u6211\u5728\u4e4b\u524d\u7684\u6587\u7ae0\u91cc\u9762\u662f\u8fd9\u6837\u8bf4\u7684\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043971755\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u4e8b\u5b9e\u4e5f\u8bc1\u660e\u4e86\uff0c\u786e\u5b9e\u662f\u5bf9\u4e8e\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u662f\u4e0d\u516c\u5e73\u7684\u3002<\/p>\n<p>\u4e8e\u662f\uff0c\u6211\u5f00\u59cb\u51c6\u5907\u7740\u624b\u6572\u4ee3\u7801\uff0c\u6253\u7b97\u518d\u6df7\u4e00\u4e2a pr\u3002<\/p>\n<p>\u6211\u60f3\u6362\u6210\u7684\u6e90\u7801\u4e5f\u5f88\u7b80\u5355\u3002\u56e0\u4e3a\u5b83\u6838\u5fc3\u76ee\u6807\u662f\u4ece list \u96c6\u5408\u4e2d\u968f\u673a\u8fd4\u56de\u4e24\u4e2a\u5bf9\u8c61\u561b\u3002<\/p>\n<p>\u90a3\u6211\u76f4\u63a5\u5c31\u662f\u8fd9\u6837\uff1a<\/p>\n<pre><code>Object invoker1 = invokerList.remove(ThreadLocalRandom.current().nextInt(invokerList.size()));\nObject invoker2 = invokerList.remove(ThreadLocalRandom.current().nextInt(invokerList.size()));<\/code><\/pre>\n<p>\u4f60\u4ed4\u7ec6\u7684\u55e6\u4e00\u55e6\u8fd9\u4e2a\u4ee3\u7801\uff0c\u662f\u4e0d\u662f\u5f88\u516c\u5e73\uff1f<\/p>\n<p>\u5f53\u4e00\u4e2a\u5143\u7d20\u88ab\u9009\u4e2d\u4e4b\u540e\uff0c\u6211\u5c31\u628a\u5b83\u7ed9\u8e22\u51fa\u53bb\u3002\u8fd9\u6837\u7b2c\u4e8c\u6b21\u968f\u673a\u7684\u65f6\u5019\uff0cinvokerList.size() \u7684\u503c\u5c31\u5b9e\u73b0\u4e86\u51cf\u4e00\u7684\u903b\u8f91\u3002<\/p>\n<p>\u65e2\u53ef\u4ee5\u4fdd\u8bc1\u7b2c\u4e8c\u6b21\u968f\u673a\u7684\u65f6\u5019\uff0c\u4e0d\u4f1a\u968f\u673a\u5230\u4e00\u6837\u7684\u5143\u7d20\u3002<\/p>\n<p>\u4e5f\u53ef\u4ee5\u4fdd\u8bc1\u5269\u4e0b\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u6709\u673a\u4f1a\u518d\u6b21\u53c2\u4e0e\u5230\u968f\u673a\u8fc7\u7a0b\u4e2d\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043971756\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u4e3a\u6b64\uff0c\u6211\u8fd8\u4e13\u95e8\u5199\u4e86\u4e00\u4e2a Demo \u6765\u9a8c\u8bc1\u8fd9\u4e2a\u5199\u6cd5\uff1a<\/p>\n<pre><code>public class MainTest {\n    private final static HashMap&lt;Integer, Integer&gt; COUNT_MAP = new HashMap&lt;&gt;();\n    \n    public static void main(String[] args) {\n        for (int i = 0; i &lt; 100000; i++) {\n            List&lt;Integer&gt; list = new ArrayList&lt;Integer&gt;();\n            list.add(1);\n            list.add(2);\n            list.add(3);\n            Integer invoker1 = list.remove(ThreadLocalRandom.current().nextInt(list.size()));\n            Integer invoker2 = list.remove(ThreadLocalRandom.current().nextInt(list.size()));\n            posCount(invoker1);\n            posCount(invoker2);\n        }\n        System.out.println(COUNT_MAP);\n    }\n\n    public static void posCount(Integer key) {\n        Integer pos1Integer = COUNT_MAP.get(key);\n        if (pos1Integer == null) {\n            COUNT_MAP.put(key, 1);\n        } else {\n            pos1Integer++;\n            COUNT_MAP.put(key, pos1Integer);\n        }\n    }\n}<\/code><\/pre>\n<p>\u4f60\u7c98\u8fc7\u53bb\u5c31\u80fd\u8dd1\uff0c\u8fd0\u884c 10w \u6b21\uff0c\u6bcf\u4e2a\u5143\u7d20\u88ab\u9009\u4e2d\u7684\u603b\u6b21\u6570\u57fa\u672c\u4e0a\u5c31\u662f 1:1:1\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043971757\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u800c\u628a Dubbo \u6e90\u7801\u91cc\u9762\u7684\u5b9e\u73b0\u62ff\u8fc7\u6765\uff1a<\/p>\n<pre><code>public class MainTest {\n\n    private final static HashMap&lt;Integer, Integer&gt; COUNT_MAP = new HashMap&lt;&gt;();\n\n    public static void main(String[] args) {\n        List&lt;Integer&gt; list = new ArrayList&lt;Integer&gt;();\n        list.add(1);\n        list.add(2);\n        list.add(3);\n        int length = list.size();\n        for (int i = 0; i &lt; 100000; i++) {\n            int pos1 = ThreadLocalRandom.current().nextInt(length);\n            int pos2 = ThreadLocalRandom.current().nextInt(length - 1);\n            if (pos2 &gt;= pos1) {\n                pos2 = pos2 + 1;\n            }\n            posCount(pos1);\n            posCount(pos2);\n        }\n        System.out.println(COUNT_MAP);\n    }\n\n    public static void posCount(Integer key) {\n        Integer pos1Integer = COUNT_MAP.get(key);\n        if (pos1Integer == null) {\n            COUNT_MAP.put(key, 1);\n        } else {\n            pos1Integer++;\n            COUNT_MAP.put(key, pos1Integer);\n        }\n    }\n}<\/code><\/pre>\n<p>\u4e5f\u8dd1 10w \u6b21\uff0c\u8fd0\u884c\u7ed3\u679c\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043971758\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>&#8230;<\/p>\n<p>&#8230;<\/p>\n<p>&#8230;<\/p>\n<p>\u5367\u69fd\uff0c\u7b49\u7b49\uff0c\u600e\u4e48\u56de\u4e8b\uff0c\u5c45\u7136\u4e5f\u662f\u63a5\u8fd1 1:1:1 \u7684\uff1f<\/p>\n<p>\u6211\u5f53\u65f6\u770b\u5230\u8fd9\u4e2a\u8fd0\u884c\u7ed3\u679c\u7684\u65f6\u5019\uff0c\u8868\u60c5\u5927\u6982\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043971759\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u8fd9\u73a9\u610f\uff0c\u548c\u6211\u5206\u6790\u51fa\u6765\u7684\u4e0d\u4e00\u6837\u554a\u3002<\/p>\n<h3>\u53cd\u8f6c<\/h3>\n<p>\u5176\u5b9e\u4e5f\u4e0d\u80fd\u7b97\u662f\u53cd\u8f6c\u5427\u3002<\/p>\n<p>\u56e0\u4e3a\u6211\u524d\u9762\u5206\u6790\u7684\u65f6\u5019\uff0c\u7ed9\u7684\u4ee3\u7801\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<pre><code>if (pos2 == pos1) {\n    pos2 = pos2 + 1;\n}<\/code><\/pre>\n<p>\u800c\u771f\u5b9e\u7684\u6e90\u7801\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<pre><code>if (pos2 &gt;= pos1) {\n    pos2 = pos2 + 1;\n}<\/code><\/pre>\n<p>\u4e00\u4e2a\u662f ==\uff0c\u4e00\u4e2a &gt;=\u3002<\/p>\n<p>\u5f53\u6211\u628a\u8fd9\u91cc\u6362\u6210 == \u7684\u65f6\u5019\uff0c\u8fd0\u884c\u7ed3\u679c\u5c31\u4e0d\u518d\u662f 1:1:1 \u4e86\uff0c\u7b26\u5408\u6211\u524d\u9762\u7a77\u4e3e\u5927\u6cd5\u5206\u6790\u7684\u60c5\u51b5\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043971760\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u800c\u5728\u6211\u7684\u6f5c\u610f\u8bc6\u91cc\u9762\uff0c\u7b2c\u4e00\u6b21\u770b\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u6211\u4e00\u76f4\u4ee5\u4e3a\u8fd9\u4e2a\u90e8\u5206\u7684\u4ee3\u7801\u5c31\u662f ==\uff0c\u6240\u4ee5\u6211\u4e00\u76f4\u6309\u7167 == \u8fdb\u884c\u7684\u5206\u6790\uff0c\u4ece\u800c\u89c9\u5f97\u5b83\u6709\u95ee\u9898\u3002<\/p>\n<p>\u8fd9\u6ce2\uff0c\u6211\u89c9\u5f97\u5f97\u8ba9\u6f5c\u610f\u8bc6\u6765\u80cc\u9505\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043971761\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u5f53\u662f &gt;= \u7684\u65f6\u5019\uff0c\u6211\u4eec\u53ea\u9700\u8981\u91cd\u65b0\u5206\u6790\u4e00\u4e0b pos1=0 \u7684\u60c5\u51b5\u3002<\/p>\n<p>\u7ec4\u5408\u4e00\uff0c0&gt;=0\uff0c\u6ee1\u8db3\u6761\u4ef6\uff0c\u6700\u7ec8 pos1=0\uff0cpos2 \u4f1a\u52a0\u4e00\uff0c\u53d8\u6210 1\uff0c\u6240\u4ee5\u8fd8\u662f\u4f1a\u53d8\u6210\u4e4b\u524d\u5206\u6790\u7684\u60c5\u51b5\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043971762\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u5f53\u65f6\u5bf9\u4e8e\u7ec4\u5408\u4e8c\uff0c\u60c5\u51b5\u5c31\u53d1\u751f\u4e86\u5fae\u5999\u7684\u53d8\u5316\u3002<\/p>\n<p>\u7ec4\u5408\u4e8c\uff0c1&gt;=0\uff0c\u6ee1\u8db3\u6761\u4ef6\uff0c\u6700\u7ec8 pos1=0\uff0cpos2 \u4f1a\u52a0\u4e00\uff0c\u53d8\u6210 2\uff0c\u6240\u4ee5\u5c31\u53d8\u6210\u4e86\u8fd9\u6837\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043971763\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>invker2 \u88ab\u66ff\u6362\u4e3a\u4e86 invoker3\u3002<\/p>\n<p>\u8fd8\u8bb0\u5f97\u6211\u4eec\u4e4b\u524d\uff0c\u6309\u7167 == \u7684\u60c5\u51b5\uff0c\u5206\u6790\u51fa\u6765\u7684\u6bd4\u4f8b\u5417\uff1f<\/p>\n<ul>\n<li>invoker1 \u88ab\u9009\u4e2d\u4e86 4 \u6b21<\/li>\n<li>invoker2 \u88ab\u9009\u4e2d\u4e86 5 \u6b21<\/li>\n<li>invoker3 \u88ab\u9009\u4e2d\u4e86 3 \u6b21<\/li>\n<\/ul>\n<p>\u6b64\u65f6\uff0c\u6211\u4eec\u6309\u7167 &gt;= \u7684\u60c5\u51b5\u5206\u6790\uff0cinvoker2 \u88ab\u66ff\u6362\u4e3a\u4e86 invoker3\u3002<\/p>\n<p>\u90a3\u4e48\u6bd4\u4f8b\u5c31\u53d8\u6210\u4e86\uff1a<\/p>\n<ul>\n<li>invoker1 \u88ab\u9009\u4e2d\u4e86 4 \u6b21<\/li>\n<li>invoker2 \u88ab\u9009\u4e2d\u4e86 4 \u6b21<\/li>\n<li>invoker3 \u88ab\u9009\u4e2d\u4e86 4 \u6b21<\/li>\n<\/ul>\n<p>\u6240\u4ee5\uff0c\u56de\u5230\u6211\u6700\u6700\u5f00\u59cb\u8bf4\u7684\u8bfb\u8005\u63d0\u51fa\u7684\u7b2c\u4e8c\u4e2a\u95ee\u9898\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043971764\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u6211\u5728\u56de\u7b54\u8bfb\u8005\u7684\u65f6\u5019\uff0c\u4e5f\u662f\u8ba4\u4e3a == \u5c31\u884c\u4e86\uff0c\u867d\u7136\u4e0d\u516c\u5e73\uff0c\u4f46\u662f\u4e5f\u4e0d\u662f\u4e0d\u80fd\u7528\u3002<\/p>\n<p>\u4f46\u662f\u7ecf\u8fc7\u524d\u9762\u8fd9\u4e00\u6ce2\u5206\u6790\u3002<\/p>\n<p>\u4e3a\u4ec0\u4e48\u4e00\u5b9a\u8981\u662f &gt;=\uff0c\u800c\u4e0d\u80fd\u53ea\u662f == \u5462\uff1f<\/p>\n<p>\u4e4b\u524d\uff0c\u6211\u4e00\u76f4\u8ba4\u4e3a\u4e0d\u516c\u5e73\u662f\u56e0\u4e3a\u6211\u8ba4\u4e3a\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u5c11\u53c2\u4e0e\u4e86\u4e00\u6b21\u968f\u673a\u3002<\/p>\n<p>\u4f46\u662f\uff0c\u7531\u4e8e &gt;= \u7684\u5b58\u5728\uff0c\u5e76\u4e0d\u4f1a\u5b58\u5728\u8fd9\u79cd\u60c5\u51b5\u3002<\/p>\n<p>\u554a\uff0c\u4e3a\u4ec0\u4e48\u4f1a\u4ea7\u751f\u4e00\u79cd\u8ba9\u6211\u60f3\u8981\u8dea\u4e0b\u7684\u611f\u89c9\uff1f<\/p>\n<p>\u6570\u5b66\uff0c\u662f\u56e0\u4e3a\u6211\u5728\u91cc\u9762\u52a0\u4e86\u6570\u5b66\u3002<\/p>\n<p>\u795e\u5947\u7684\u3001\u4ee4\u4eba\u53c8\u4e0a\u5934\u53c8\u7740\u8ff7\u7684\u6570\u5b66\u3002<\/p>\n<h2>\u8352\u8154\u8d70\u677f<\/h2>\n<p>\u5728\u8fd9\u4e2a\u4e8b\u60c5\u4e0a\uff0c\u6211\u6574\u4e2a\u5fc3\u6001\u662f\u4ece\u81ea\u4fe1\u6ee1\u6ee1\u5230\u4e00\u5730\u9e21\u6bdb\uff0c\u8fd9\u4e2a\u5fc3\u8def\u5386\u7a0b\u8ba9\u6211\u60f3\u8d77\u4e86\u6211\u5927\u5b66\u7684\u65f6\u5019\uff0c\u5b66\u8fc7\u7684\u4e00\u95e8\u8bfe\u7a0b\u53eb\u505a\u300a\u7ebf\u6027\u4ee3\u6570\u300b\u3002<\/p>\n<p>\u5f53\u65f6\u6211\u5b66\u7684\u53ef\u8ba4\u771f\uff0c\u8001\u5e08\u8bb2\u7684\u6bcf\u8282\u8bfe\u6211\u611f\u89c9\u6211\u90fd\u542c\u61c2\u4e86\uff0c\u671f\u672b\u8003\u8bd5\u7684\u8fc7\u7a0b\u4e2d\uff0c\u5305\u62ec\u8003\u5b8c\u4e4b\u540e\u6211\u90fd\u662f\u4fe1\u5fc3\u6ee1\u6ee1\u7684\u6837\u5b50\uff0c\u89c9\u5f97\u8fd9\u9898\u4e5f\u4e0d\u96be\u554a\u3002<\/p>\n<p>\u968f\u968f\u4fbf\u4fbf\u8003\u4e2a\u516b\u5341\u591a\u5206\u95ee\u9898\u4e0d\u5927\u5427\u3002<\/p>\n<p>\u6700\u540e\uff0c\u8003\u8bd5\u7ed3\u679c\u51fa\u6765\u7684\u65f6\u5019\u6211\u6ca1\u53ca\u683c\uff0c\u6211\u8bb0\u5f97\u662f 56 \u5206\u8fd8\u662f 58 \u5206\u7684\u6837\u5b50\uff0c\u53cd\u6b63\u5dee\u4e00\u70b9\u70b9\u53ca\u683c\uff0c\u8fd9\u8bfe\u5c45\u7136\u6302\u4e86\uff1f<\/p>\n<p>\u6211\u5f53\u65f6\u5728\u5bbf\u820d\u5c31\u62cd\u6848\u800c\u8d77\uff1a\u80af\u5b9a\u6709\u95ee\u9898\uff0c\u6211\u8981\u6c42\u67e5\u5377\uff0c\u6211\u505a\u9898\u7684\u65f6\u5019\u5f88\u6709\u81ea\u4fe1\u554a\u3002<\/p>\n<p>\u7136\u540e\u6211\u8981\u5230\u4e86\u8001\u5e08\u7684\u8054\u7cfb\u65b9\u5f0f\uff0c\u5e76\u81ea\u62a5\u5bb6\u95e8\uff0c\u8bf4\u660e\u60c5\u51b5\uff0c\u6211\u575a\u6301\u8ba4\u4e3a\u5e94\u8be5\u662f\u67d0\u4e2a\u73af\u8282\u51fa\u4e86\u95ee\u9898\uff0c\u770b\u770b\u80fd\u4e0d\u80fd\u628a\u5377\u5b50\u627e\u51fa\u6765\u518d\u770b\u770b\u3002<\/p>\n<p>\u540e\u6765\u554a&#8230;<\/p>\n<p>\u8001\u5e08\u628a\u5377\u5b50\u62cd\u7167\u53d1\u7ed9\u6211\u4e86\uff0c\u786e\u5b9e\u662f\u67d0\u4e2a\u73af\u8282\u51fa\u4e86\u95ee\u9898\uff0c\u8fd9\u4e2a\u73af\u8282\u5c31\u662f\u6211\u81ea\u5df1\u3002<\/p>\n<p>\u6211\u548c\u7b54\u6848\u5bf9\u4e86\u4e00\u4e0b\uff0c\u5377\u9762\u5c31\u53ea\u6709 40 \u591a\u5206\u7684\u6837\u5b50\u3002<\/p>\n<p>\u6700\u7ec8\u6210\u7ee9\u6709 50 \u591a\u5206\u662f\u56e0\u4e3a\u8001\u5e08\u8fd8\u7b97\u4e86\u5e73\u65f6\u5206\uff0c\u7531\u4e0a\u8bfe\u51fa\u52e4\u7387\u548c\u65e5\u5e38\u4f5c\u4e1a\u5b8c\u6210\u60c5\u51b5\u7efc\u5408\u7b97\u51fa\u6765\u7684\u3002<\/p>\n<p>\u90a3\u5929\uff0c\u6211\u7ad9\u5728\u5bbf\u820d\u7684\u9633\u53f0\u4e0a\uff0c\u770b\u7740\u624b\u673a\u4e0a\u7684\u8bd5\u5377\u7167\u7247\uff0c\u518d\u6311\u773c\u770b\u5411\u8fdc\u65b9\uff0c\u5915\u9633\u897f\u4e0b\uff0c\u6b8b\u9633\u5982\u8840\uff0c\u516d\u697c\u7684\u98ce\u513f\u751a\u81f3\u55a7\u56a3\uff0c\u8086\u610f\u7684\u5728\u6211\u8138\u4e0a\u62c2\u8fc7\u3002<\/p>\n<p>\u697c\u4e0b\u7199\u7199\u6518\u6518\u7684\u5b66\u751f\u8d70\u8fc7\uff0c\u65f6\u4e0d\u65f6\u7684\u7206\u53d1\u51fa\u4e00\u9635\u9635\u94f6\u94c3\u822c\u7684\u7b11\u58f0\uff0c\u6211\u53ea\u662f\u89c9\u5f97\u5435\u95f9\u3002<\/p>\n<p>\u968f\u540e\uff0c\u6211\u95ee\u5ba4\u53cb\uff1a\u4ec0\u4e48\u65f6\u5019\u8865\u8003\uff1f\u6709\u6ca1\u6709\u4eba\u80fd\u7ed9\u6211\u8865\u4e60\u4e00\u4e0b\uff1f<\/p>\n<p>\u6570\u5b66\uff0c\u554a\uff0c\u8fd9\u795e\u5947\u7684\u3001\u4ee4\u4eba\u53c8\u4e0a\u5934\u53c8\u7740\u8ff7\u7684\u6570\u5b66\u3002<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000043971738\">https:\/\/segmentfault.com\/a\/1190000043971738<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f60\u597d\u5440\uff0c\u6211\u662f\u6b6a\u6b6a\u3002 \u4e0a\u5468\u6211\u4e0d\u662f\u53d1\u4e86\u300a\u6211\u8bd5\u56fe\u7ed9\u4f60\u5206\u4eab\u4e00\u79cd\u81ea\u9002\u5e94\u7684\u8d1f\u8f7d\u5747\u8861\u3002\u300b\u8fd9\u7bc7\u6587\u7ae0\u561b\uff0c\u91cc\u9762\u4e00\u79cd\u53eb\u505a\u201c\u81ea\u9002\u5e94\u8d1f\u8f7d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10008039","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008039","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10008039"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008039\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10008039"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10008039"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10008039"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}