{"id":10007053,"date":"2023-01-09T18:13:13","date_gmt":"2023-01-09T10:13:13","guid":{"rendered":"https:\/\/ityet.com\/?p=10007053"},"modified":"2023-01-09T18:13:13","modified_gmt":"2023-01-09T10:13:13","slug":"%e8%99%bd%e7%84%b6%e6%98%af%e6%88%91%e9%81%87%e5%88%b0%e7%9a%84%e4%b8%80%e4%b8%aa%e6%a3%98%e6%89%8b%e7%9a%84%e7%94%9f%e4%ba%a7%e9%97%ae%e9%a2%98%ef%bc%8c%e4%bd%86%e6%98%af%e6%88%91%e5%86%99%e5%87%ba","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10007053","title":{"rendered":"\u867d\u7136\u662f\u6211\u9047\u5230\u7684\u4e00\u4e2a\u68d8\u624b\u7684\u751f\u4ea7\u95ee\u9898\uff0c\u4f46\u662f\u6211\u5199\u51fa\u6765\u4e4b\u540e\uff0c\u5c31\u662f\u4f60\u7684\u4e86\u3002"},"content":{"rendered":"<p>\u4f60\u597d\u5440\uff0c\u662f\u6b6a\u6b6a\u3002<\/p>\n<p>\u524d\u51e0\u5929\uff0c\u5c31\u5728\u5927\u5bb6\u8fd8\u6c89\u6d78\u5728\u7b49\u5f85\u6625\u8282\u5230\u6765\u7684\u559c\u60a6\u6c1b\u56f4\u7684\u65f6\u5019\uff0c\u5728\u4e00\u4e2a\u6838\u5fc3\u94fe\u8def\u4e0a\u7684\u6838\u5fc3\u7cfb\u7edf\u4e2d\uff0c\u6211\u8e29\u5230\u4e00\u4e2a\u5751\u7684\u4e00\u6bd4\u7684\u5751\uff0c\u8981\u4e0d\u662f\u6211\u6c89\u7740\u51b7\u9759\uff0c\u89e3\u51b3\u601d\u8def\u5fd9\u4e2d\u6709\u5e8f\uff0c\u5904\u7406\u624b\u6bb5\u96f7\u5389\u98ce\u884c\uff0c\u628a\u5b83\u7ed9\u627c\u6740\u5728\u840c\u82bd\u9636\u6bb5\u4e86\uff0c\u90a3\u8fd9\u73a9\u610f\u80af\u5b9a\u5f97\u5f15\u53d1\u4e00\u4e2a\u6bd4\u8f83\u4e25\u91cd\u7684\u751f\u4ea7\u95ee\u9898\u3002<\/p>\n<p>\u4ece\u95ee\u9898\u51fa\u73b0\u5230\u5b9a\u4f4d\u5230\u8fd9\u4e2a\u95ee\u9898\u7684\u6839\u672c\u539f\u56e0\uff0c\u6211\u5927\u6982\u662f\u82b1\u4e86\u4e24\u5929\u534a\u7684\u65f6\u95f4\u3002<\/p>\n<p>\u6240\u4ee5\u5199\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u590d\u76d8\u4e00\u4e0b\u554a\uff0c\u8fd9\u4e2a\u6848\u4f8b\u5c31\u662f\u4e00\u4e2a\u7eaf\u6280\u672f\u7684\u95ee\u9898\u5bfc\u81f4\u7684\uff0c\u548c\u4e1a\u52a1\u7684\u76f8\u5173\u5ea6\u5176\u5b9e\u5e76\u4e0d\u5927\uff0c\u6240\u4ee5\u4f60\u62ff\u8fc7\u53bb\u76f4\u63a5\u6dfb\u6cb9\u52a0\u918b\uff0c\u7a0d\u5fae\u6539\u6539\uff0c\u5f80\u81ea\u5df1\u7684\u670d\u52a1\u4e0a\u5957\u4e00\u4e0b\uff0c\u90a3\u5c31\u662f\u4f60\u7684\u4e86\u3002<\/p>\n<p>\u6211\u518d\u8bf4\u4e00\u6b21\uff1a<strong>\u867d\u7136\u73b0\u5728\u4e0d\u662f\u4f60\u7684\uff0c\u4f46\u662f\u4f60\u770b\u5b8c\u4e4b\u540e\u5c31\u662f\u4f60\u7684\u4e86\uff0c\u4f60\u660e\u767d\u6211\u610f\u601d\u5427\uff1f<\/strong><\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279523\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h2>\u8868\u8c61<\/h2>\n<p>\u4e8b\u60c5\u662f\u8fd9\u6837\u7684\uff0c\u6211\u8fd9\u8fb9\u6709\u4e00\u4e2a\u670d\u52a1\uff0c\u4f60\u53ef\u4ee5\u628a\u8fd9\u4e2a\u670d\u52a1\u7c97\u66b4\u7684\u7406\u89e3\u4e3a\u662f\u4e00\u4e2a\u5546\u57ce\u4e00\u6837\u7684\u670d\u52a1\u3002\u6709\u5546\u57ce\u80af\u5b9a\u5c31\u6709\u4e0b\u5355\u561b\u3002<\/p>\n<p>\u7136\u540e\u63a5\u5230\u4e0a\u6e38\u670d\u52a1\u53cd\u9988\uff0c\u8bf4\u8c03\u7528\u4e0b\u5355\u63a5\u53e3\u5076\u5c14\u6709\u8c03\u7528\u8d85\u65f6\u7684\u60c5\u51b5\u51fa\u73b0\uff0c\u65ad\u65ad\u7eed\u7eed\u7684\u51fa\u73b0\u597d\u51e0\u6b21\u4e86\uff0c\u7ed9\u4e86\u51e0\u7b14\u6d41\u6c34\u53f7\uff0c\u8ba9\u6211\u770b\u4e00\u4e0b\u5565\u60c5\u51b5\u3002\u5f53\u65f6\u6211\u7684\u7b2c\u4e00\u53cd\u5e94\u662f\u4e0d\u53ef\u80fd\u662f\u6211\u8fd9\u8fb9\u670d\u52a1\u7684\u95ee\u9898\uff0c\u56e0\u4e3a\u8fd9\u4e2a\u670d\u52a1\u4e0a\u6b21\u4e0a\u7ebf\u90fd\u81f3\u5c11\u662f\u4e00\u4e2a\u591a\u6708\u524d\u7684\u4e8b\u60c5\u4e86\uff0c\u6240\u4ee5\u4e0d\u53ef\u80fd\u662f\u7531\u4e8e\u8fd1\u671f\u670d\u52a1\u6295\u4ea7\u5bfc\u81f4\u7684\u3002<\/p>\n<p>\u4f46\u662f\u4e0b\u5355\u63a5\u53e3\uff0c\u4f60\u542c\u540d\u5b57\u5c31\u77e5\u9053\u4e86\uff0c\u6838\u5fc3\u94fe\u63a5\u4e0a\u7684\u6838\u5fc3\u529f\u80fd\uff0c\u4e0d\u80fd\u6709\u4e00\u70b9\u9ebb\u75f9\u5927\u610f\u3002<\/p>\n<p>\u6bcf\u4e00\u4e2a\u8bf7\u6c42\u90fd\u5f88\u91cd\u8981\uff0c\u5ba2\u6237\u4e0b\u5355\u4f53\u9a8c\u4e0d\u597d\uff0c\u53ef\u80fd\u5c31\u4e0d\u4e70\u4e86\uff0c\u9020\u6210\u4ea4\u6613\u635f\u5931\u3002<\/p>\n<p>\u4ea4\u6613\u4e0a\u4e0d\u53bb\u8425\u4e1a\u989d\u5c31\u4e0a\u4e0d\u53bb\uff0c\u8425\u4e1a\u989d\u4e0a\u4e0d\u53bb\u5229\u6da6\u5c31\u4e0a\u4e0d\u53bb\uff0c\u5229\u6da6\u4e0a\u4e0d\u53bb\u5e74\u7ec8\u5c31\u4e0a\u4e0d\u53bb\u3002<\/p>\n<p>\u60f3\u5230\u8fd9\u4e00\u5c42\u5173\u7cfb\u4e4b\u540e\uff0c\u6211\u7acb\u9a6c\u5c31\u767b\u9646\u5230\u670d\u52a1\u5668\u4e0a\uff0c\u5f00\u59cb\u5b9a\u4f4d\u95ee\u9898\u3002<\/p>\n<p>\u4e00\u770b\u65e5\u5fd7\uff0c\u786e\u5b9e\u662f\u6211\u8fd9\u8fb9\u63a5\u53e3\u8bf7\u6c42\u5904\u7406\u6162\u4e86\uff0c\u5bfc\u81f4\u7684\u8c03\u7528\u65b9\u8d85\u65f6\u3002<\/p>\n<p>\u4e3a\u4ec0\u4e48\u4f1a\u6162\u5462\uff1f<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279524\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u4e8e\u662f\u6309\u7167\u5e38\u89c4\u601d\u8def\u5148\u6839\u636e\u65e5\u5fd7\u5224\u65ad\u4e86\u4e00\u4e0b\u4e0b\u5355\u63a5\u53e3\u4e2d\u8c03\u7528\u5176\u4ed6\u670d\u52a1\u7684\u63a5\u53e3\u76f8\u5e94\u662f\u5426\u6b63\u5e38\uff0c\u4ece\u6570\u636e\u5e93\u83b7\u53d6\u6570\u636e\u7684\u65f6\u95f4\u662f\u5426\u6b63\u5e38\u3002<\/p>\n<p>\u8fd9\u4e9b\u5224\u65ad\u6ca1\u95ee\u9898\u4e4b\u540e\uff0c\u6211\u8f6c\u800c\u628a\u76ee\u5149\u653e\u5230\u4e86 gc \u4e0a\uff0c\u901a\u8fc7\u76d1\u63a7\u53d1\u73b0\u90a3\u4e2a\u65f6\u95f4\u70b9\u89e6\u53d1\u4e86\u4e00\u6b21\u8017\u65f6\u63a5\u8fd1 1s \u7684 full gc\uff0c\u5bfc\u81f4\u54cd\u5e94\u6162\u4e86\u3002<\/p>\n<p>\u7531\u4e8e\u6211\u4eec\u76d1\u63a7\u53ea\u91c7\u96c6\u670d\u52a1\u8fd1\u4e00\u5468\u7684 gc \u6570\u636e\uff0c\u6240\u4ee5\u6211\u628a\u65f6\u95f4\u62c9\u957f\u540e\u53d1\u73b0 full gc \u5728\u8fd9\u4e00\u5468\u7684\u65f6\u95f4\u5185\u51fa\u73b0\u7684\u9891\u7387\u8fd8\u6709\u70b9\u9ad8\uff0c\u867d\u7136\u6211\u8fd8\u6ca1\u5b9a\u4f4d\u5230\u95ee\u9898\u7684\u6839\u672c\u539f\u56e0\uff0c\u4f46\u662f\u6211\u5b9a\u4f4d\u5230\u4e86\u95ee\u9898\u7684\u8868\u9762\u539f\u56e0\uff0c\u5c31\u662f\u89e6\u53d1\u4e86 full gc\u3002<\/p>\n<p>\u56e0\u4e3a\u662f\u6838\u5fc3\u94fe\u8def\uff0c\u6838\u5fc3\u6d41\u7a0b\uff0c\u6240\u4ee5\u6b64\u65f6\u4e0d\u5e94\u8be5\u6025\u7740\u53bb\u5b9a\u4f4d\u6839\u672c\u539f\u56e0\uff0c\u800c\u662f\u5148\u7f13\u89e3\u95ee\u9898\u3002<\/p>\n<p>\u597d\u5728\u6211\u4eec\u63d0\u524d\u51c6\u5907\u4e86\u5404\u79cd\u539f\u56e0\u7684\u5e94\u6025\u9884\u6848\uff0c\u5176\u4e2d\u5c31\u5305\u542b\u8fd9\u4e2a\u573a\u666f\u3002\u9884\u6848\u7684\u5185\u5bb9\u5c31\u662f\u6269\u5927\u5e94\u7528\u5806\u5185\u5b58\uff0c\u5ef6\u7f13 full gc \u7684\u51fa\u73b0\u3002<\/p>\n<p>\u6240\u4ee5\u6211\u5f53\u5373\u8fdb\u884c\u64cd\u4f5c\u62a5\u5907\u5e76\u8054\u7cfb\u8fd0\u7ef4\uff0c\u6309\u7167\u7d27\u6025\u9884\u6848\u6267\u884c\uff0c\u628a\u670d\u52a1\u7684\u5806\u5185\u5b58\u7531 8G \u6269\u5927\u4e00\u500d\uff0c\u63d0\u5347\u5230 16G\u3002<\/p>\n<p>\u867d\u7136\u8fd9\u4e2a\u65b9\u6cd5\u7b80\u5355\u7c97\u66b4\uff0c\u4f46\u662f\u65e2\u89e3\u51b3\u4e86\u5f53\u524d\u7684\u8c03\u7528\u8d85\u65f6\u7684\u95ee\u9898\uff0c\u4e5f\u7ed9\u4e86\u6211\u8db3\u591f\u7684\u6392\u67e5\u95ee\u9898\u7684\u65f6\u95f4\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279525\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h2>\u5b9a\u4f4d\u539f\u56e0<\/h2>\n<p>\u5f53\u65f6\u6211\u5176\u5b9e\u4e00\u70b9\u90fd\u4e0d\u614c\u7684\uff0c\u56e0\u4e3a\u95ee\u9898\u5728\u840c\u82bd\u9636\u6bb5\u7684\u65f6\u5019\u6211\u5c31\u628a\u5b83\u7ed9\u5e72\u6389\u4e86\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279526\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u4e0d\u5c31\u662f full gc \u5417\uff0c\u54e6\uff0c\u6211\u7684\u8001\u670b\u53cb\u3002<\/p>\n<p>\u5148\u5927\u80c6\u5047\u8bbe\u4e00\u6ce2\uff1a\u7a0b\u5e8f\u91cc\u9762\u67d0\u4e2a\u903b\u8f91\u4e0d\u5c0f\u5fc3\u641e\u51fa\u4e86\u5927\u5bf9\u8c61\uff0c\u89e6\u53d1\u4e86 full gc\u3002<\/p>\n<p>\u6240\u4ee5\u6211\u5148\u662f\u53cc\u624b\u63d2\u515c\uff0c\u5e26\u7740\u76d1\u63a7\u56fe\u548c\u65e5\u5fd7\u8bf7\u6c42\uff0c\u95f2\u5ead\u4fe1\u6b65\u7684\u8d70\u8fdb\u9879\u76ee\u4ee3\u7801\u91cc\u9762\uff0c\u60f3\u8981\u51ed\u501f\u8089\u773c\u627e\u51fa\u4e00\u70b9\u86db\u4e1d\u9a6c\u8ff9&#8230;&#8230;<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279527\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u6ca1\u6709\u4efb\u4f55\u6536\u83b7\uff0c\u56e0\u4e3a\u4e0b\u5355\u670d\u52a1\u6d89\u53ca\u5230\u7684\u903b\u8f91\u771f\u7684\u662f\u592a\u591a\u4e86\uff0c\u670d\u52a1\u91cc\u9762 List \u548c Map \u968f\u5904\u53ef\u89c1\uff0c\u6211\u5f88\u96be\u627e\u5230\u5230\u5e95\u54ea\u91cc\u662f\u5927\u5bf9\u8c61\u3002<\/p>\n<p>\u4f46\u662f\u6211\u8fd8\u662f\u4e00\u70b9\u90fd\u4e0d\u614c\uff0c\u56e0\u4e3a\u8fd9\u534a\u5929\u90fd\u6ca1\u6709\u518d\u6b21\u53d1\u751f Full GC\uff0c\u8bf4\u660e\u6b64\u65f6\u7559\u7ed9\u6211\u7684\u65f6\u95f4\u8fd8\u662f\u6bd4\u8f83\u5145\u8db3\u7684\uff0c<\/p>\n<p>\u6240\u4ee5\u6211\u8bf7\u6c42\u4e86\u573a\u5916\u63f4\u52a9\uff0c\u8ba9 DBA \u5e2e\u6211\u5bfc\u51fa\u4e00\u4e0b\u670d\u52a1\u7684\u6162\u67e5\u8be2 SQL\uff0c\u56e0\u4e3a\u6211\u60f3\u53ef\u80fd\u662f\u4ece\u6570\u636e\u5e93\u91cc\u9762\u4e00\u6b21\u6027\u53d6\u7684\u6570\u636e\u592a\u591a\u4e86\uff0c\u800c\u7a0b\u5e8f\u91cc\u9762\u4e5f\u6ca1\u6709\u505a\u63a7\u5236\u5bfc\u81f4\u7684\u3002<\/p>\n<p>\u6211\u4e4b\u524d\u5c31\u8e29\u8fc7\u7c7b\u4f3c\u7684\u5751\u3002<\/p>\n<p>\u4e00\u4e2a\u6839\u636e\u5ba2\u6237\u53f7\u67e5\u8be2\u5ba2\u6237\u6709\u591a\u5c11\u8ba2\u5355\u7684\u5185\u90e8\u4f7f\u7528\u63a5\u53e3\uff0c\u63a5\u53e3\u7684\u8fd4\u56de\u662f List&lt;\u8ba2\u5355&gt;\uff0c\u770b\u8d77\u6765\u6ca1\u5565\u6bdb\u75c5\uff0c\u5bf9\u4e0d\u5bf9\uff1f<\/p>\n<p>\u4e00\u822c\u6765\u8bf4\u4e00\u4e2a\u4e2a\u4eba\u5ba2\u6237\u5c31\u51e0\u5341\u4e0a\u767e\uff0c\u591a\u4e00\u70b9\u7684\u4e0a\u5343\uff0c\u9876\u5929\u4e86\u7684\u4e0a\u4e07\u4e2a\u8ba2\u5355\uff0c\u4e00\u6b21\u6027\u62ff\u51fa\u6765\u4e5f\u4e0d\u662f\u4e0d\u53ef\u4ee5\u3002<\/p>\n<p>\u4f46\u662f\u6709\u4e00\u4e2a\u5ba2\u6237\u4e0d\u77e5\u9053\u548b\u56de\u4e8b\uff0c\u7279\u522b\u949f\u7231\u6211\u4eec\u7684\u5e73\u53f0\uff0c\u4e5f\u662f\u6211\u4eec\u5e73\u53f0\u7684\u8001\u5ba2\u6237\u4e86\uff0c\u4e00\u4e2a\u4eba\u5c45\u7136\u6709\u63a5\u8fd1 10w \u7684\u8ba2\u5355\u3002<\/p>\n<p>\u7136\u540e\u8fd9\u4e48\u591a\u8ba2\u5355\u5bf9\u8c61\u641e\u5230\u5230\u9879\u76ee\u91cc\u9762\uff0c\u672c\u6765\u54cd\u5e94\u5c31\u6709\u70b9\u6162\uff0c\u4e0a\u6e38\u518d\u53d1\u8d77\u51e0\u6b21\u91cd\u8bd5\uff0c\u76f4\u63a5\u89e6\u53d1 Full gc\uff0c\u964d\u4f4e\u4e86\u670d\u52a1\u54cd\u5e94\u65f6\u95f4\u3002<\/p>\n<p>\u6240\u4ee5\uff0c\u7ecf\u8fc7\u8fd9\u4e2a\u4e8b\u4ef6\uff0c\u6211\u4eec\u5b9a\u4e86\u4e00\u4e2a\u89c4\u77e9\uff1a\u7528 List\u3001Map \u6765\u4f5c\u4e3a\u8fd4\u56de\u5bf9\u8c61\u7684\u65f6\u5019\uff0c\u5fc5\u987b\u8981\u8003\u8651\u4e00\u4e0b\u6781\u7aef\u60c5\u51b5\u4e0b\u4f1a\u8fd4\u56de\u591a\u5c11\u6570\u636e\u56de\u53bb\u3002\u5373\u4f7f\u662f\u5185\u90e8\u4f7f\u7528\uff0c\u4e5f\u6700\u597d\u662f\u8fdb\u884c\u5206\u9875\u67e5\u8be2\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u8bdd\u8bf4\u56de\u6765\uff0c\u6211\u62ff\u5230\u6162\u67e5\u8be2 SQL \u4e4b\u540e\uff0c\u6839\u636e\u51e0\u4e2a Full gc \u65f6\u95f4\u70b9\uff0c\u5bf9\u6bd4\u4e4b\u540e\u63d0\u53d6\u51fa\u4e86\u51e0\u6761\u770b\u8d77\u6765\u6709\u70b9\u95ee\u9898\u7684 SQL\u3002<\/p>\n<p>\u7136\u540e\u62ff\u5230\u6570\u636e\u5e93\u6267\u884c\u4e86\u4e00\u4e0b\uff0c\u53d1\u73b0\u8fd4\u56de\u7684\u6570\u636e\u91cf\u5176\u5b9e\u4e5f\u90fd\u4e0d\u5927\u3002<\/p>\n<p>\u6b64\u523b\u6211\u8fd8\u662f\u4e00\u70b9\u90fd\u4e0d\u614c\uff0c\u53cd\u6b63\u5185\u5b58\u591f\u7528\uff0c\u800c\u4e14\u9488\u5bf9\u8fd9\u7c7b\u95ee\u9898\uff0c\u6211\u8fd8\u6709\u4e00\u4e2a\u573a\u5916\u63f4\u52a9\u6ca1\u6709\u4f7f\u7528\u5462\u3002<\/p>\n<p>\u7b2c\u4e8c\u5929\u6211\u5f00\u59cb\u627e\u8fd0\u7ef4\u540c\u4e8b\u5e2e\u6211\u6bcf\u9694 8 \u5c0f\u65f6 Dump \u4e00\u6b21\u5185\u5b58\u6587\u4ef6\uff0c\u7136\u540e\u7b2c\u4e09\u5929\u6211\u5f00\u59cb\u62ff\u7740\u5185\u5b58\u6587\u4ef6\u6162\u6162\u5206\u6790\u3002<\/p>\n<p>\u4f46\u662f\u7b2c\u4e8c\u5929\u6211\u4e5f\u6ca1\u95f2\u7740\uff0c\u6839\u636e\u73b0\u6709\u7684\u7ebf\u7d22\u53cd\u590d\u5206\u6790\u3001\u63a8\u7406\u53ef\u80fd\u7684\u539f\u56e0\u3002<\/p>\n<p>\u7136\u540e\u5728\u89c2\u770b GC \u56de\u6536\u5185\u5b58\u5927\u5c0f\u76d1\u63a7\u7684\u65f6\u5019\uff0c\u53d1\u73b0\u4e86\u4e00\u70b9\u70b9\u7aef\u502a\u3002\u56e0\u4e3a\u89e6\u53d1 Full GC \u4e4b\u540e\uff0c\u53d1\u73b0\u88ab\u56de\u6536\u7684\u5806\u5185\u5b58\u4e5f\u4e0d\u662f\u7279\u522b\u591a\u3002<\/p>\n<p>\u5f53\u65f6\u5c31\u60f3\u5230\u4e86\u9664\u4e86\u5927\u5bf9\u8c61\u4e4b\u5916\uff0c\u8fd8\u6709\u4e00\u4e2a\u73b0\u8c61\u6709\u53ef\u80fd\u4f1a\u5bfc\u81f4\u8fd9\u4e2a\u73b0\u8c61\uff1a\u5185\u5b58\u6cc4\u9732\u3002<\/p>\n<p>\u5de7\u7684\u662f\u5728\u7b2c\u4e8c\u5929\u53c8\u53d1\u751f\u4e86\u4e00\u6b21 Full gc\uff0c\u8fd9\u6837\u6211\u62ff\u5230\u7684 Dump \u6587\u4ef6\u5c31\u66f4\u6709\u5206\u6790\u7684\u4ef7\u503c\u4e86\u3002\u57fa\u4e8e\u524d\u9762\u7684\u731c\u60f3\uff0c\u6211\u5206\u6790\u7684\u65f6\u5019\u76f4\u63a5\u5c31\u51b2\u7740\u5185\u5b58\u6cc4\u6f0f\u7684\u65b9\u5411\u53bb\u67e5\u4e86\u3002<\/p>\n<p>\u6211\u62ff\u7740 5 \u4e2a Dump \u6587\u4ef6\uff0c\u5206\u6790\u4e86\u5728 5 \u4e2a Dump \u6587\u4ef6\u4e2d\u5bf9\u8c61\u6570\u91cf\u4e00\u76f4\u5728\u589e\u52a0\u7684\u5bf9\u8c61\uff0c\u8fd9\u6837\u7684\u5bf9\u8c61\u4e5f\u4e0d\u5c11\uff0c\u4f46\u662f\u6700\u7ec8\u5b9a\u4f4d\u5230\u4e86 FutureTask \u5bf9\u8c61\uff0c\u5c31\u662f\u5b83\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279528\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u627e\u5230\u8fd9\u73a9\u610f\u4e86\u518d\u56de\u53bb\u5b9a\u4f4d\u5bf9\u5e94\u90e8\u5206\u7684\u4ee3\u7801\u5c31\u6bd4\u8f83\u5bb9\u6613\u3002<\/p>\n<p>\u4f46\u662f\u4f60\u4ee5\u4e3a\u5b9a\u4f4d\u4e86\u4ee3\u7801\u5c31\u5b8c\u4e8b\u4e86\u5417\uff1f<\/p>\n<p>\u4e0d\u662f\u7684\uff0c\u5230\u8fd9\u91cc\u624d\u521a\u521a\u5f00\u59cb\uff0c\u670b\u53cb\u3002<\/p>\n<p>\u56e0\u4e3a\u6211\u53d1\u73b0\u8fd9\u4e2a\u4ee3\u7801\u5bf9\u5e94\u7684 Bug \u9690\u85cf\u7684\u8fd8\u662f\u6bd4\u8f83\u6df1\u7684\uff0c\u800c\u4e14\u4e5f\u4e0d\u662f\u6211\u6700\u5f00\u59cb\u5047\u8c61\u7684\u5185\u5b58\u6cc4\u9732\uff0c\u5c31\u662f\u4e00\u4e2a\u7eaf\u7cb9\u7684\u5185\u5b58\u6ea2\u51fa\u3002<\/p>\n<p>\u6240\u4ee5\u503c\u5f97\u62ff\u51fa\u6765\u4ed4\u7ec6\u55e6\u4e00\u55e6\u3002<\/p>\n<h2>\u793a\u4f8b\u4ee3\u7801<\/h2>\n<p>\u4e3a\u4e86\u8ba9\u4f60\u6c89\u6d78\u5f0f\u4f53\u9a8c\u627e BUG \u7684\u8fc7\u7a0b\uff0c\u6211\u9ad8\u4f4e\u5f97\u7ed9\u4f60\u6574\u4e00\u4e2a\u53ef\u590d\u73b0\u7684 Demo \u51fa\u6765\uff0c\u4f60\u62ff\u8fc7\u53bb\u5c31\u53ef\u4ee5\u8dd1\u7684\u90a3\u79cd\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u5f97\u641e\u4e00\u4e2a\u7ebf\u7a0b\u6c60\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279529\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u9700\u8981\u8bf4\u660e\u4e00\u4e0b\u7684\u662f\uff0c\u4e0a\u9762\u8fd9\u4e2a\u7ebf\u7a0b\u6c60\u7684\u6838\u5fc3\u7ebf\u7a0b\u6570\u3001\u6700\u5927\u7ebf\u7a0b\u6570\u548c\u961f\u5217\u957f\u5ea6\u6211\u90fd\u53d6\u7684 1\uff0c\u53ea\u662f\u4e3a\u4e86\u65b9\u4fbf\u6f14\u793a\u95ee\u9898\uff0c\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\u662f\u4e00\u4e2a\u6bd4\u8f83\u5408\u7406\u7684\u503c\u3002<\/p>\n<p>\u7136\u540e\u91cd\u70b9\u770b\u4e00\u4e0b\u7ebf\u7a0b\u6c60\u91cc\u9762\u6709\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u53eb\u505a MyThreadFactory \u7684\u7ebf\u7a0b\u5de5\u5382\u7c7b\u548c\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u53eb\u505a MyRejectedPolicy \u7684\u62d2\u7edd\u7b56\u7565\u3002<\/p>\n<p>\u5728\u6211\u7684\u670d\u52a1\u91cc\u9762\u5c31\u662f\u6709\u8fd9\u6837\u4e00\u4e2a\u53eb\u505a product \u7684\u7ebf\u7a0b\u6c60\uff0c\u7528\u7684\u4e5f\u662f\u8fd9\u4e2a\u81ea\u5b9a\u4e49\u62d2\u7edd\u7b56\u7565\u3002<\/p>\n<p>\u5176\u4e2d MyThreadFactory \u7684\u4ee3\u7801\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279530\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u5b83\u548c\u9ed8\u8ba4\u7684\u7ebf\u7a0b\u5de5\u5382\u4e4b\u95f4\u552f\u4e00\u7684\u533a\u522b\u5c31\u662f\u6211\u52a0\u4e86\u4e00\u4e2a threadFactoryName \u5b57\u6bb5\uff0c\u65b9\u4fbf\u7ed9\u7ebf\u7a0b\u6c60\u91cc\u9762\u7684\u7ebf\u7a0b\u53d6\u4e00\u4e2a\u5408\u9002\u7684\u540d\u5b57\u3002<\/p>\n<p>\u66f4\u76f4\u89c2\u7684\u8868\u793a\u4e00\u4e0b\u533a\u522b\u5c31\u662f\u4e0b\u9762\u8fd9\u4e2a\u73a9\u610f\uff1a<\/p>\n<blockquote><p>\u539f\u751f\uff1apool-1-thread-1<br \/>\u81ea\u5b9a\u4e49\uff1aproduct-pool-1-thread-1<\/p><\/blockquote>\n<p>\u63a5\u4e0b\u6765\u770b\u81ea\u5b9a\u4e49\u7684\u62d2\u7edd\u7b56\u7565\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279531\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u8fd9\u91cc\u7684\u903b\u8f91\u5f88\u7b80\u5355\uff0c\u5c31\u662f\u5f53 product \u7ebf\u7a0b\u6c60\u6ee1\u4e86\uff0c\u89e6\u53d1\u4e86\u62d2\u7edd\u7b56\u7565\u7684\u65f6\u5019\u6253\u5370\u4e00\u884c\u65e5\u5fd7\uff0c\u65b9\u4fbf\u540e\u7eed\u5b9a\u4f4d\u3002<\/p>\n<p>\u7136\u540e\u63a5\u7740\u770b\u5176\u4ed6\u90e8\u5206\u7684\u4ee3\u7801\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279532\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u6807\u53f7\u4e3a \u2460 \u7684\u5730\u65b9\u662f\u7ebf\u7a0b\u6c60\u91cc\u9762\u8fd0\u884c\u7684\u4efb\u52a1\uff0c\u6211\u8fd9\u91cc\u53ea\u662f\u4e00\u4e2a\u793a\u610f\uff0c\u6240\u4ee5\u903b\u8f91\u975e\u5e38\u7b80\u5355\uff0c\u5c31\u662f\u628a i \u6269\u5927 10 \u500d\u3002\u5b9e\u9645\u9879\u76ee\u4e2d\u8fd0\u884c\u7684\u4efb\u52a1\u4e1a\u52a1\u903b\u8f91\uff0c\u4f1a\u590d\u6742\u4e00\u70b9\uff0c\u4f46\u662f\u4e5f\u662f\u6709\u4e00\u4e2a Future \u8fd4\u56de\u3002<\/p>\n<p>\u6807\u53f7\u4e3a \u2461 \u7684\u5730\u65b9\u5c31\u662f\u628a\u8fd4\u56de\u7684 Future \u653e\u5230 list \u96c6\u5408\u4e2d\uff0c\u5728\u6807\u53f7\u4e3a \u2462 \u7684\u5730\u65b9\u5faa\u73af\u5904\u7406\u8fd9\u4e2a list \u5bf9\u8c61\u91cc\u9762\u7684 Future\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\u56e0\u4e3a\u5b9e\u4f8b\u4e2d\u7684\u7ebf\u7a0b\u6c60\u6700\u591a\u5bb9\u7eb3\u4e24\u4e2a\u4efb\u52a1\uff0c\u4f46\u662f\u8fd9\u91cc\u5374\u6709\u4e94\u4e2a\u4efb\u52a1\u3002\u6211\u8fd9\u6837\u5199\u7684\u76ee\u7684\u5c31\u662f\u4e3a\u4e86\u65b9\u4fbf\u89e6\u53d1\u62d2\u7edd\u7b56\u7565\u3002<\/p>\n<p>\u7136\u540e\u5728\u5b9e\u9645\u7684\u9879\u76ee\u91cc\u9762\u521a\u521a\u63d0\u5230\u7684\u8fd9\u4e00\u5768\u903b\u8f91\u662f\u901a\u8fc7\u5b9a\u65f6\u4efb\u52a1\u89e6\u53d1\u7684\uff0c\u6240\u4ee5\u6211\u8fd9\u91cc\u7528\u4e00\u4e2a\u6b7b\u5faa\u73af\u52a0\u624b\u52a8\u5f00\u542f\u7ebf\u7a0b\u6765\u793a\u610f\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279533\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u6574\u4e2a\u5b8c\u6574\u7684\u4ee3\u7801\u5c31\u662f\u8fd9\u6837\u7684\uff0c\u4f60\u76f4\u63a5\u7c98\u8fc7\u53bb\u5c31\u53ef\u4ee5\u8dd1\uff0c\u8fd9\u4e2a\u6848\u4f8b\u5c31\u53ef\u4ee5\u5b8c\u5168\u590d\u73b0\u6211\u5728\u751f\u4ea7\u4e0a\u9047\u5230\u7684\u95ee\u9898\uff1a<\/p>\n<pre><code>public class MainTest {\n\n    public static void main(String[] args) throws Exception {\n\n        ThreadPoolExecutor productThreadPoolExecutor = new ThreadPoolExecutor(1,\n                1,\n                1,\n                TimeUnit.SECONDS,\n                new LinkedBlockingQueue&lt;&gt;(1),\n                new MyThreadFactory(&quot;product&quot;),\n                new MyRejectedPolicy());\n\n        while (true){\n            TimeUnit.SECONDS.sleep(1);\n            new Thread(()-&gt;{\n                ArrayList&lt;Future&lt;Integer&gt;&gt; futureList = new ArrayList&lt;&gt;();\n                \/\/\u4ece\u6570\u636e\u5e93\u83b7\u53d6\u4ea7\u54c1\u4fe1\u606f\n                int productNum = 5;\n                for (int i = 0; i &lt; productNum; i++) {\n                    try {\n                        int finalI = i;\n                        Future&lt;Integer&gt; future = productThreadPoolExecutor.submit(() -&gt; {\n                            System.out.println(&quot;Thread.currentThread().getName() = &quot; + Thread.currentThread().getName());\n                            return finalI * 10;\n                        });\n                        futureList.add(future);\n                    } catch (Exception e) {\n                        e.printStackTrace();\n                    }\n                }\n                for (Future&lt;Integer&gt; integerFuture : futureList) {\n                    try {\n                        Integer integer = integerFuture.get();\n                        System.out.println(integer);\n                        System.out.println(&quot;future.get() = &quot; + integer);\n                    } catch (Exception e) {\n                        e.printStackTrace();\n                    }\n                }\n            }).start();\n        }\n\n    }\n\n    static class MyThreadFactory implements ThreadFactory {\n        private static final AtomicInteger poolNumber = new AtomicInteger(1);\n        private final ThreadGroup group;\n        private final AtomicInteger threadNumber = new AtomicInteger(1);\n        private final String namePrefix;\n        private final String threadFactoryName;\n\n        public String getThreadFactoryName() {\n            return threadFactoryName;\n        }\n\n        MyThreadFactory(String threadStartName) {\n            SecurityManager s = System.getSecurityManager();\n            group = (s != null) ? s.getThreadGroup() :\n                    Thread.currentThread().getThreadGroup();\n            namePrefix = threadStartName + &quot;-pool-&quot; +\n                    poolNumber.getAndIncrement() +\n                    &quot;-thread-&quot;;\n            threadFactoryName = threadStartName;\n        }\n\n        public Thread newThread(Runnable r) {\n            Thread t = new Thread(group, r,\n                    namePrefix + threadNumber.getAndIncrement(),\n                    0);\n            if (t.isDaemon())\n                t.setDaemon(false);\n            if (t.getPriority() != Thread.NORM_PRIORITY)\n                t.setPriority(Thread.NORM_PRIORITY);\n            return t;\n        }\n    }\n\n    public static class MyRejectedPolicy implements RejectedExecutionHandler {\n\n        @Override\n        public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {\n            if (e.getThreadFactory() instanceof MyThreadFactory) {\n                MyThreadFactory myThreadFactory = (MyThreadFactory) e.getThreadFactory();\n                if (&quot;product&quot;.equals(myThreadFactory.getThreadFactoryName())) {\n                    System.out.println(THREAD_FACTORY_NAME_PRODUCT + &quot;\u7ebf\u7a0b\u6c60\u6709\u4efb\u52a1\u88ab\u62d2\u7edd\u4e86,\u8bf7\u5173\u6ce8&quot;);\n                }\n            }\n        }\n    }\n}<\/code><\/pre>\n<p>\u4f60\u8dd1\u7684\u65f6\u5019\u53ef\u4ee5\u628a\u5806\u5185\u5b58\u8bbe\u7f6e\u7684\u5c0f\u4e00\u70b9\uff0c\u6bd4\u5982\u6211\u8bbe\u7f6e\u4e3a 10m\uff1a<\/p>\n<blockquote><p>-Xmx10m -Xms10m<\/p><\/blockquote>\n<p>\u7136\u540e\u7528 jconsole \u76d1\u63a7\uff0c\u4f60\u4f1a\u53d1\u73b0\u5185\u5b58\u8d70\u52bf\u56fe\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279534\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u54e6\uff0c\u6211\u7684\u8001\u5929\u7237\u554a\uff0c\u8fd9\u4e2a\u8be5\u6b7b\u7684\u56fe\uff0c\u4e5f\u662f\u6211\u7684\u8001\u4f19\u8ba1\u4e86\uff0c\u4e00\u4e2a\u7f13\u6162\u7684\u6301\u7eed\u4e0a\u5347\u7684\u5185\u5b58\u8d8b\u52bf\u56fe\uff0c \u6700\u540e\u75af\u72c2\u7684\u89e6\u53d1 gc\uff0c\u4f46\u662f\u5e76\u6ca1\u6709\u5185\u5b58\u88ab\u56de\u6536\uff0c\u6700\u540e\u7a0b\u5e8f\u76f4\u63a5\u5d29\u6389\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279535\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u8fd9\u7edd\u5927\u6982\u7387\u5c31\u662f\u5185\u5b58\u6cc4\u6f0f\u4e86\u554a\u3002<\/p>\n<p>\u4f46\u662f\u5728\u751f\u4ea7\u4e0a\u7684\u5185\u5b58\u8d70\u52bf\u56fe\u5b8c\u5168\u770b\u4e0d\u51fa\u6765\u8fd9\u4e2a\u8d8b\u52bf\uff0c\u6211\u524d\u9762\u8bf4\u4e86\uff0c\u4e3b\u8981\u56e0\u4e3a GC \u60c5\u51b5\u7684\u6570\u636e\u53ea\u4f1a\u4fdd\u7559\u4e00\u5468\u65f6\u95f4\uff0c\u6240\u4ee5\u5c31\u7b97\u628a\u6574\u4e2a\u56fe\u653e\u51fa\u6765\u4e5f\u4e0d\u662f\u90a3\u4e48\u76f4\u89c2\u3002<\/p>\n<p>\u5176\u6b21\u4e0d\u662f\u56e0\u4e3a\u6211\u725b\u903c\u561b\uff0c\u840c\u82bd\u9636\u6bb5\u5c31\u5e72\u6389\u4e86\u8fd9\u4e2a\u95ee\u9898\uff0c\u6240\u4ee5\u6ca1\u6709\u9047\u5230\u6700\u540e\u9891\u7e41\u89e6\u53d1 gc\uff0c\u4f46\u662f\u6ca1\u5565\u56de\u6536\u7684\uff0c\u5bfc\u81f4 OOM \u7684\u60c5\u51b5\u3002<\/p>\n<p>\u6240\u4ee5\u6211\u518d\u5e26\u7740\u4f60\u770b\u770b\u53e6\u5916\u4e00\u4e2a\u89c6\u89d2\uff0c\u8fd9\u662f\u6211\u771f\u6b63\u5b9a\u4f4d\u5230\u95ee\u9898\u7684\u89c6\u89d2\u3002\u5c31\u662f\u5206\u6790\u5185\u5b58 Dump \u6587\u4ef6\u3002<\/p>\n<p>\u5206\u6790\u5185\u5b58 Dump \u6587\u4ef6\u7684\u5de5\u5177\u4ee5\u53ca\u76f8\u5173\u7684\u6587\u7ae0\u975e\u5e38\u7684\u591a\uff0c\u6211\u5c31\u4e0d\u8d58\u8ff0\u4e86\uff0c\u4f60\u968f\u4fbf\u627e\u4e2a\u5de5\u5177\u73a9\u4e00\u73a9\u5c31\u884c\u3002\u6211\u8fd9\u91cc\u4e3b\u8981\u662f\u5206\u4eab\u4e00\u4e2a\u601d\u8def\uff0c\u6240\u4ee5\u5c31\u76f4\u63a5\u4f7f\u7528 idea \u91cc\u9762\u7684 Profiler \u63d2\u4ef6\u4e86\uff0c\u65b9\u4fbf\u3002<\/p>\n<p>\u6211\u7528\u4e0a\u9762\u7684\u4ee3\u7801\uff0c\u542f\u52a8\u8d77\u6765\u4e4b\u540e\u5728\u56db\u4e2a\u65f6\u95f4\u70b9\u5206\u522b Dump \u4e4b\u540e\uff0c\u89c2\u5bdf\u5185\u5b58\u6587\u4ef6\u3002\u5185\u5b58\u6cc4\u9732\u7684\u601d\u8def\u5c31\u662f\u627e\u6587\u4ef6\u91cc\u9762\u54ea\u4e2a\u5bf9\u8c61\u7684\u4e2a\u6570\u548c\u5360\u7528\u7a7a\u95f4\u662f\u5728\u6301\u7eed\u4e0a\u5347\u561b\uff0c\u7279\u522b\u662f\u4e2d\u95f4\u8fd8\u53d1\u751f\u8fc7 full gc\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u5176\u5b9e\u662f\u4e00\u4e2a\u6bd4\u8f83\u67af\u71e5\u4e14\u590d\u6742\u7684\u8fc7\u7a0b\uff0c\u5728\u751f\u4ea7\u9879\u76ee\u4e2d\u53ef\u80fd\u4f1a\u5206\u6790\u51fa\u5f88\u591a\u4e2a\u8fd9\u6837\u7684\u5bf9\u8c61\uff0c\u7136\u540e\u90fd\u8981\u5230\u4ee3\u7801\u91cc\u9762\u53bb\u5b9a\u4f4d\u76f8\u5173\u903b\u8f91\u3002<\/p>\n<p>\u4f46\u662f\u6211\u8fd9\u91cc\u6781\u5927\u7684\u7b80\u5316\u4e86\u7a0b\u5e8f\uff0c\u6240\u4ee5\u5f88\u5bb9\u6613\u5c31\u4f1a\u53d1\u73b0\u8fd9\u4e2a FutureTask \u5bf9\u8c61\u7279\u522b\u7684\u62a2\u773c\uff0c\u6570\u91cf\u5728\u6301\u7eed\u589e\u52a0\uff0c\u800c\u4e14\u8fd8\u662f\u540d\u5217\u524d\u8305\u7684\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279536\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u7136\u540e\u8fd9\u4e2a\u5de5\u5177\u8fd8\u53ef\u4ee5\u770b\u5bf9\u8c61\u5360\u7528\u5927\u5c0f\uff0c\u5927\u6982\u662f\u8fd9\u4e2a\u610f\u601d\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279537\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u6240\u4ee5\u6211\u8fd8\u53ef\u4ee5\u770b\u770b\u5728\u8fd9\u51e0\u4e2a\u6587\u4ef6\u4e2d FutureTask \u5bf9\u8c61\u5927\u5c0f\u7684\u53d8\u5316\uff0c\u4e5f\u662f\u6301\u7eed\u589e\u52a0\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279538\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u5c31\u5b83\u4e86\uff0c\u51c6\u6ca1\u9519\u3002<\/p>\n<p>\u597d\uff0c\u95ee\u9898\u5df2\u7ecf\u80fd\u590d\u73b0\u4e86\uff0cGC \u56fe\u548c\u5185\u5b58 Dump \u7684\u56fe\u4e5f\u90fd\u7ed9\u4f60\u770b\u4e86\u3002<\/p>\n<p>\u5230\u8fd9\u91cc\uff0c\u5982\u679c\u6709\u4eba\u5df2\u7ecf\u770b\u51fa\u6765\u95ee\u9898\u7684\u539f\u56e0\u4e86\uff0c\u53ef\u4ee5\u76f4\u63a5\u62c9\u5230\u6587\u672b\u70b9\u4e2a\u8d5e\uff0c\u611f\u8c22\u5927\u4f6c\u9605\u8bfb\u6211\u7684\u6587\u7ae0\u3002<\/p>\n<p>\u5982\u679c\u4f60\u8fd8\u6ca1\u770b\u51fa\u7aef\u502a\u6765\uff0c\u90a3\u4e48\u6211\u5148\u7ed9\u4f60\u8bf4\u95ee\u9898\u7684\u6839\u672c\u539f\u56e0\uff1a<\/p>\n<blockquote><p>\u95ee\u9898\u7684\u6839\u672c\u539f\u56e0\u5c31\u51fa\u5728 MyRejectedPolicy \u8fd9\u4e2a\u81ea\u5b9a\u4e49\u62d2\u7edd\u7b56\u7565\u4e0a\u3002<\/p><\/blockquote>\n<p>\u5728\u5e26\u4f60\u7ec6\u55e6\u8fd9\u4e2a\u95ee\u9898\u4e4b\u524d\uff0c\u6211\u5148\u95ee\u4e00\u4e2a\u95ee\u9898\uff1a<\/p>\n<blockquote><p>JDK \u81ea\u5e26\u7684\u7ebf\u7a0b\u6c60\u62d2\u7edd\u7b56\u7565\u6709\u54ea\u4e9b\uff1f<\/p><\/blockquote>\n<p>\u8fd9\u73a9\u610f\uff0c\u8001\u516b\u80a1\u6587\u4e86\uff0c\u5b58\u5728\u7684\u65f6\u95f4\u6bd4\u6211\u4ece\u4e1a\u7684\u65f6\u95f4\u90fd\u957f\uff0c\u5f97\u5f20\u53e3\u5c31\u6765\uff1a<\/p>\n<ul>\n<li>AbortPolicy\uff1a\u4e22\u5f03\u4efb\u52a1\u5e76\u629b\u51fa RejectedExecutionException \u5f02\u5e38\uff0c\u8fd9\u662f\u9ed8\u8ba4\u7684\u7b56\u7565\u3002<\/li>\n<li>DiscardOldestPolicy\uff1a\u4e22\u5f03\u961f\u5217\u6700\u524d\u9762\u7684\u4efb\u52a1\uff0c\u6267\u884c\u540e\u9762\u7684\u4efb\u52a1<\/li>\n<li>CallerRunsPolicy\uff1a\u7531\u8c03\u7528\u7ebf\u7a0b\u5904\u7406\u8be5\u4efb\u52a1<\/li>\n<li>DiscardPolicy\uff1a\u4e5f\u662f\u4e22\u5f03\u4efb\u52a1\uff0c\u4f46\u662f\u4e0d\u629b\u51fa\u5f02\u5e38\uff0c\u76f8\u5f53\u4e8e\u9759\u9ed8\u5904\u7406\u3002<\/li>\n<\/ul>\n<p>\u7136\u540e\u4f60\u518d\u56de\u5934\u770b\u770b\u6211\u7684\u81ea\u5b9a\u4e49\u62d2\u7edd\u7b56\u7565\uff0c\u662f\u4e0d\u662f\u548c DiscardPolicy \u975e\u5e38\u50cf\uff0c\u4e5f\u6ca1\u6709\u629b\u51fa\u5f02\u5e38\u3002\u53ea\u662f\u6bd4\u5b83\u66f4\u9ad8\u7ea7\u4e00\u70b9\uff0c\u6253\u5370\u4e86\u4e00\u70b9\u65e5\u5fd7\u3002<\/p>\n<p>\u5f53\u6211\u4eec\u4f7f\u7528\u9ed8\u8ba4\u7684\u7b56\u7565\u7684\u65f6\u5019\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279539\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u6216\u8005\u6211\u4eec\u628a\u6846\u8d77\u6765\u8fd9\u884c\u4ee3\u7801\u7c98\u5230\u6211\u4eec\u7684 MyRejectedPolicy \u7b56\u7565\u91cc\u9762\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279540\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u518d\u6b21\u8fd0\u884c\uff0c\u4e0d\u7ba1\u662f\u89c2\u5bdf gc \u60c5\u51b5\uff0c\u8fd8\u662f Dump \u5185\u5b58\uff0c\u4f60\u4f1a\u53d1\u73b0\u7a0b\u5e8f\u6b63\u5e38\u4e86\uff0c\u6ca1\u6bdb\u75c5\u4e86\u3002<\/p>\n<p>\u4e0b\u9762\u8fd9\u4e2a\u8d70\u52bf\u56fe\u5c31\u662f\u5728\u62d2\u7edd\u7b56\u7565\u4e2d\u662f\u5426\u629b\u51fa\u5f02\u5e38\u5bf9\u5e94\u7684\u5185\u5b58\u8d70\u52bf\u5bf9\u6bd4\u56fe\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279541\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u5728\u62d2\u7edd\u7b56\u7565\u4e2d\u629b\u51fa\u5f02\u5e38\u5c31\u6ca1\u6bdb\u75c5\u4e86\uff0c\u4e3a\u5565\uff1f<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279542\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h2>\u63a2\u7d22<\/h2>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u6765\u770b\u4e00\u4e0b\u6ca1\u6709\u629b\u51fa\u5f02\u5e38\u7684\u65f6\u5019\uff0c\u53d1\u751f\u4e86\u4ec0\u4e48\u4e8b\u60c5\u3002<\/p>\n<p>\u6ca1\u6709\u629b\u51fa\u5f02\u5e38\u65f6\uff0c\u6211\u4eec\u524d\u9762\u5206\u6790\u4e86\uff0c\u51fa\u73b0\u4e86\u975e\u5e38\u591a\u7684 FutureTask \u5bf9\u8c61\uff0c\u6240\u4ee5\u6211\u4eec\u5c31\u627e\u7a0b\u5e8f\u91cc\u9762\u8fd9\u4e2a\u5bf9\u8c61\u662f\u54ea\u91cc\u51fa\u6765\u7684\uff0c\u5b9a\u4f4d\u5230\u8fd9\u4e2a\u5730\u65b9\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279543\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>future \u6ca1\u6709\u88ab\u56de\u6536\uff0c\u8bf4\u660e futureList \u5bf9\u8c61\u6ca1\u6709\u88ab\u56de\u6536\uff0c\u800c\u8fd9\u4e24\u4e2a\u5bf9\u8c61\u5bf9\u5e94\u7684 GC Root \u90fd\u662fnew \u51fa\u6765\u7684\u8fd9\u4e2a\u7ebf\u7a0b\uff0c\u56e0\u4e3a\u4e00\u4e2a\u6d3b\u8dc3\u7ebf\u7a0b\u662f GC Root\u3002<\/p>\n<p>\u8fdb\u4e00\u6b65\u8bf4\u660e\u5bf9\u5e94 new \u51fa\u6765\u7684\u7ebf\u7a0b\u6ca1\u6709\u88ab\u56de\u6536\u3002<\/p>\n<p>\u6240\u4ee5\u6211\u7ed9\u4f60\u770b\u4e00\u4e0b\u524d\u9762\u4e24\u4e2a\u6848\u4f8b\u5bf9\u5e94\u7684\u7ebf\u7a0b\u6570\u5bf9\u6bd4\u56fe\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279544\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u6ca1\u6709\u5728\u62d2\u7edd\u7b56\u7565\u4e2d\u629b\u51fa\u5f02\u5e38\u7684\u7ebf\u7a0b\u975e\u5e38\u7684\u591a\uff0c\u770b\u8d77\u6765\u6bcf\u4e00\u4e2a\u90fd\u6ca1\u6709\u88ab\u56de\u6536\uff0c\u8fd9\u4e2a\u5730\u65b9\u80af\u5b9a\u5c31\u662f\u6709\u95ee\u9898\u7684\u3002<\/p>\n<p>\u7136\u540e\u968f\u673a\u9009\u4e00\u4e2a\u67e5\u770b\u8be6\u60c5\uff0c\u53ef\u4ee5\u770b\u5230\u7ebf\u7a0b\u5728\u7b2c 39 \u884c\u5361\u7740\u7684\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279545\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u4e5f\u5c31\u662f\u8fd9\u6837\u4e00\u884c\u4ee3\u7801\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279546\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u8fd9\u4e2a\u65b9\u6cd5\u5927\u5bb6\u5e94\u8be5\u719f\u6089\uff0c\u56e0\u4e3a\u4e5f\u6ca1\u6709\u7ed9\u7b49\u5f85\u65f6\u95f4\u561b\uff0c\u6240\u4ee5\u5982\u679c\u7b49\u4e0d\u5230 Future \u7684\u7ed3\u679c\uff0c\u7ebf\u7a0b\u5c31\u4f1a\u5728\u8fd9\u91cc\u6b7b\u7b49\u3002<\/p>\n<p>\u4e5f\u5c31\u5bfc\u81f4\u7ebf\u7a0b\u4e0d\u4f1a\u8fd0\u884c\u7ed3\u675f\uff0c\u6240\u4ee5\u4e0d\u4f1a\u88ab\u56de\u6536\u3002<\/p>\n<p>\u5bf9\u5e94\u7740\u6e90\u7801\u8bf4\u5c31\u662f\u6709 Future \u7684 state \u5b57\u6bb5\uff0c\u5373\u72b6\u6001\u4e0d\u6b63\u786e\uff0c\u5bfc\u81f4\u7ebf\u7a0b\u963b\u585e\u5728\u8fd9\u4e2a if \u91cc\u9762\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279547\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>if \u91cc\u9762\u7684 awaitDone \u903b\u8f91\u7a0d\u5fae\u6709\u4e00\u70b9\u70b9\u590d\u6742\uff0c\u8fd9\u4e2a\u5730\u65b9\u5176\u5b9e\u8fd8\u6709\u4e00\u4e2a BUG\uff0c\u5728 JDK 9 \u8fdb\u884c\u4e86\u4fee\u590d\uff0c\u8fd9\u4e00\u70b9\u6211\u5728\u4e4b\u524d\u7684\u6587\u7ae0\u4e2d\u5199\u8fc7\uff0c\u6240\u4ee5\u5c31\u4e0d\u8d58\u8ff0\u4e86\uff0c\u4f60\u6709\u5174\u8da3\u53ef\u4ee5\u53bb\u770b\u770b\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=aMbJd1XEAHkuqx61XhKblg%3D%3D.Ywv4bvpGx%2FULjhvNprHDDvrtSqLGfJC%2FcxXJsKmYeXitZocdHtqoPKsS4c0aWltlZH%2Bqi38xvN4RJ2DdJLAEMA%3D%3D\" rel=\"nofollow\">\u300aDoug Lea\u5728J.U.C\u5305\u91cc\u9762\u5199\u7684BUG\u53c8\u88ab\u7f51\u53cb\u53d1\u73b0\u4e86\u3002\u300b<\/a><\/p>\n<p>\u603b\u4e4b\uff0c\u5728\u6211\u4eec\u7684\u6848\u4f8b\u4e0b\uff0c\u6700\u7ec8\u4f1a\u8d70\u5230\u6211\u6846\u8d77\u6765\u7684\u4ee3\u7801\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279548\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u4e5f\u5c31\u662f\u5f53\u524d\u7ebf\u7a0b\u4f1a\u5728\u8fd9\u91cc\u963b\u585e\u4f4f\uff0c\u7b49\u5230\u5524\u9192\u3002<\/p>\n<p>\u90a3\u4e48\u95ee\u9898\u5c31\u6765\u4e86\uff0c\u8c01\u6765\u5524\u9192\u5b83\u5462\uff1f<\/p>\n<p>\u5de7\u4e86\uff0c\u8fd9\u4e2a\u95ee\u9898\u6211\u4e4b\u524d\u4e5f\u5199\u8fc7\uff0c\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6709\u8fd9\u6837\u4e00\u53e5\u8bdd\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=ClNrbyPtxA6orDyDSiRV3w%3D%3D.IMs9Xoh%2FF%2F66dMBJy9GJua6pJSF2prX%2BaqtPcosqOBZglbyLS0hlvHC9ac%2FFe5YAK%2ByPFIeLziFHrAz5hshOYA%3D%3D\" rel=\"nofollow\">\u300a\u5173\u4e8e\u591a\u7ebf\u7a0b\u4e2d\u629b\u5f02\u5e38\u7684\u8fd9\u4e2a\u9762\u8bd5\u9898\u6211\u518d\u8bf4\u6700\u540e\u4e00\u6b21\uff01\u300b<\/a><\/p>\n<blockquote><p>\u5982\u679c\u5b50\u7ebf\u7a0b\u6355\u83b7\u4e86\u5f02\u5e38\uff0c\u8be5\u5f02\u5e38\u4e0d\u4f1a\u88ab\u5c01\u88c5\u5230 Future \u91cc\u9762\u3002\u662f\u901a\u8fc7 FutureTask \u7684 run \u65b9\u6cd5\u91cc\u9762\u7684 setException \u548c set \u65b9\u6cd5\u5b9e\u73b0\u7684\u3002\u5728\u8fd9\u4e24\u4e2a\u65b9\u6cd5\u91cc\u9762\u5b8c\u6210\u4e86 FutureTask \u91cc\u9762\u7684 outcome \u53d8\u91cf\u7684\u8bbe\u7f6e\uff0c\u540c\u65f6\u5b8c\u6210\u4e86\u4ece NEW \u5230 NORMAL \u6216\u8005 EXCEPTIONAL \u72b6\u6001\u7684\u6d41\u8f6c\u3002<\/p><\/blockquote>\n<p>\u5e26\u4f60\u770b\u4e00\u773c FutureTask \u7684 run \u65b9\u6cd5\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279549\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u4e5f\u5c31\u662f\u8bf4 FutureTask \u72b6\u6001\u53d8\u5316\u7684\u903b\u8f91\u662f\u88ab\u5c01\u88c5\u5230\u5b83\u7684 run \u65b9\u6cd5\u91cc\u9762\u7684\u3002<\/p>\n<p>\u77e5\u9053\u4e86\u5b83\u5728\u54ea\u91cc\u7b49\u5f85\uff0c\u5728\u54ea\u91cc\u5524\u9192\uff0c\u63ed\u6653\u7b54\u6848\u4e4b\u524d\uff0c\u8fd8\u5f97\u5e26\u4f60\u53bb\u770b\u4e00\u4e0b\u5b83\u5728\u54ea\u91cc\u8bde\u751f\u3002<\/p>\n<p>\u5b83\u7684\u51fa\u751f\u5730\uff0c\u5c31\u662f\u7ebf\u7a0b\u6c60\u7684 submit \u65b9\u6cd5\uff1a<\/p>\n<blockquote><p>java.util.concurrent.AbstractExecutorService#submit<\/p><\/blockquote>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279550\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u4f46\u662f\uff0c\u670b\u53cb\uff0c\u6ce8\u610f\uff0c\u6211\u8981\u8bf4\u4f46\u662f\u4e86\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u770b\u4e00\u4e0b\u5f53\u7ebf\u7a0b\u6c60\u7684 execute \u65b9\u6cd5\uff0c\u5f53\u7ebf\u7a0b\u6c60\u6ee1\u4e86\u4e4b\u540e\uff0c\u518d\u6b21\u63d0\u4ea4\u4efb\u52a1\u4f1a\u89e6\u53d1 reject \u65b9\u6cd5\uff0c\u800c\u5f53\u524d\u7684\u4efb\u52a1\u5e76\u4e0d\u4f1a\u88ab\u653e\u5230\u961f\u5217\u91cc\u9762\u53bb\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279551\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u4e5f\u5c31\u662f\u8bf4\u5f53 submit \u65b9\u6cd5\u4e0d\u629b\u51fa\u5f02\u5e38\u5c31\u4f1a\u628a\u6b63\u5e38\u8fd4\u56de\u7684\u8fd9\u4e2a\u72b6\u6001\u4e3a NEW \u7684 future \u653e\u5230 futureList \u91cc\u9762\u53bb\uff0c\u5373\u4e0b\u9762\u7f16\u53f7\u4e3a \u2460 \u7684\u5730\u65b9\u3002\u7136\u540e\u88ab\u6807\u53f7\u4e3a \u2461 \u7684\u5faa\u73af\u65b9\u6cd5\u5904\u7406\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279552\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u90a3\u4e48\u95ee\u9898\u5c31\u6765\u4e86\uff1a\u88ab\u62d2\u7edd\u4e86\u7684\u4efb\u52a1\uff0c\u8fd8\u4f1a\u88ab\u7ebf\u7a0b\u6c60\u89e6\u53d1 run \u65b9\u6cd5\u5417\uff1f<\/p>\n<p>\u80af\u5b9a\u662f\u4e0d\u4f1a\u7684\uff0c\u90fd\u88ab\u62d2\u7edd\u4e86\uff0c\u8fd8\u89e6\u53d1\u4e2a\u6bdb\u7ebf\u554a\u3002<\/p>\n<p>\u4e0d\u4f1a\u88ab\u89e6\u53d1 run \u65b9\u6cd5\uff0c\u90a3\u4e48\u8fd9\u4e2a future \u7684\u72b6\u6001\u5c31\u4e0d\u4f1a\u4ece NEW \u53d8\u5316\u5230 EXCEPTION \u6216\u8005 NORMAL\u3002<\/p>\n<p>\u6240\u4ee5\u8c03\u7528 Future.get() \u65b9\u6cd5\u5c31\u4e00\u5b9a\u4e00\u76f4\u963b\u585e\u3002\u53c8\u56e0\u4e3a\u662f\u5b9a\u65f6\u4efb\u52a1\u89e6\u53d1\u7684\u903b\u8f91\uff0c\u6240\u4ee5\u5bfc\u81f4 Future \u5bf9\u8c61\u8d8a\u6765\u8d8a\u591a\uff0c\u5f62\u6210\u4e00\u79cd\u5185\u5b58\u6cc4\u9732\u3002<\/p>\n<p>submit \u65b9\u6cd5\u5982\u679c\u629b\u51fa\u5f02\u5e38\u5219\u4f1a\u88ab\u6807\u53f7\u4e3a \u2461 \u7684\u5730\u65b9\u6355\u83b7\u5230\u5f02\u5e38\u3002<\/p>\n<p>\u4e0d\u4f1a\u6267\u884c\u6807\u53f7\u4e3a \u2460 \u7684\u5730\u65b9\uff0c\u4e5f\u5c31\u4e0d\u4f1a\u5bfc\u81f4\u5185\u5b58\u6cc4\u9732\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279553\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u9053\u7406\u5c31\u662f\u8fd9\u4e48\u4e00\u4e2a\u9053\u7406\u3002<\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p>\u77e5\u9053\u95ee\u9898\u7684\u6839\u672c\u539f\u56e0\u4e86\uff0c\u89e3\u51b3\u65b9\u6848\u4e5f\u5f88\u7b80\u5355\u3002<\/p>\n<p>\u5b9a\u4f4d\u5230\u8fd9\u4e2a\u95ee\u9898\u4e4b\u540e\uff0c\u6211\u53d1\u73b0\u9879\u76ee\u4e2d\u7684\u7ebf\u7a0b\u6c60\u53c2\u6570\u914d\u7f6e\u7684\u5e76\u4e0d\u5408\u7406\uff0c\u6bcf\u6b21\u5b9a\u65f6\u4efb\u52a1\u89e6\u53d1\u4e4b\u540e\uff0c\u56e0\u4e3a\u6570\u636e\u5e93\u91cc\u9762\u7684\u6570\u636e\u8f83\u591a\uff0c\u6240\u4ee5\u90fd\u4f1a\u89e6\u53d1\u62d2\u7edd\u7b56\u7565\u3002<\/p>\n<p>\u6240\u4ee5\u9996\u5148\u662f\u8c03\u6574\u4e86\u7ebf\u7a0b\u6c60\u7684\u53c2\u6570\uff0c\u8ba9\u5b83\u66f4\u52a0\u7684\u5408\u7406\u3002\u5f53\u65f6\u5982\u679c\u4f60\u8981\u7528\u8fd9\u4e2a\u6848\u4f8b\uff0c\u8fd9\u4e2a\u5730\u65b9\u4f60\u4e5f\u53ef\u4ee5\u5305\u88c5\u4e00\u4e0b\uff0c\u52a8\u6001\u7ebf\u7a0b\u6c60\uff0c\u9ad8\u5927\u4e0a\uff0c\u5bf9\u5427\uff0c\u4ee5\u524d\u8bb2\u8fc7\u3002<\/p>\n<p>\u7136\u540e\u662f\u8c03\u7528 Future.get() \u65b9\u6cd5\u7684\u65f6\u5019\uff0c\u7ed9\u4e00\u4e2a\u8d85\u65f6\u65f6\u95f4\uff0c\u8fd9\u6837\u81f3\u5c11\u80fd\u5e2e\u6211\u4eec\u515c\u4e2a\u5e95\u3002\u8d44\u6e90\u80fd\u53ca\u65f6\u91ca\u653e\uff0c\u6bd4\u6b7b\u7b49\u597d\u3002<\/p>\n<p>\u6700\u540e\u5c31\u662f\u4e00\u4e2a\u6559\u8bad\uff1a\u81ea\u5b9a\u4e49\u7ebf\u7a0b\u6c60\u62d2\u7edd\u7b56\u7565\u7684\u65f6\u5019\uff0c\u4e00\u5b9a\u4e00\u5b9a\u8bb0\u5f97\u8981\u8003\u8651\u5230\u8fd9\u4e2a\u573a\u666f\u3002<\/p>\n<p>\u6bd4\u5982\u6211\u524d\u9762\u629b\u51fa\u5f02\u5e38\u7684\u81ea\u5b9a\u4e49\u62d2\u7edd\u7b56\u7565\u5176\u5b9e\u8fd8\u662f\u6709\u95ee\u9898\u7684\uff0c\u6211\u6545\u610f\u7559\u4e0b\u4e86\u4e00\u4e2a\u5751\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279554\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u629b\u51fa\u5f02\u5e38\u7684\u524d\u63d0\u662f\u8981\u6ee1\u8db3\u6700\u5f00\u59cb\u7684 if \u6761\u4ef6\uff1a<\/p>\n<blockquote><p>e.getThreadFactory() instanceof MyThreadFactory<\/p><\/blockquote>\n<p>\u5982\u679c\u522b\u4eba\u8bef\u7528\u4e86\u8fd9\u4e2a\u62d2\u7edd\u7b56\u7565\uff0c\u5bfc\u81f4\u8fd9\u4e2a if \u6761\u4ef6\u4e0d\u6210\u7acb\u7684\u8bdd\uff0c\u90a3\u4e48\u8fd9\u4e2a\u62d2\u7edd\u7b56\u7565\u8fd8\u662f\u6709\u95ee\u9898\u3002<\/p>\n<p>\u6240\u4ee5\uff0c\u5e94\u8be5\u628a\u629b\u51fa\u5f02\u5e38\u7684\u903b\u8f91\u79fb\u5230 if \u4e4b\u5916\u3002<\/p>\n<p>\u540c\u65f6\u5728\u6392\u67e5\u95ee\u9898\u7684\u8fc7\u7a0b\u4e2d\uff0c\u5728\u9879\u76ee\u91cc\u9762\u770b\u5230\u4e86\u7c7b\u4f3c\u8fd9\u6837\u7684\u5199\u6cd5\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279555\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u4e0d\u8981\u8fd9\u6837\u5199\uff0c\u597d\u5417\uff1f<\/p>\n<p>\u4e00\u4e2a\u662f\u56e0\u4e3a submit \u662f\u6709\u8fd4\u56de\u503c\u7684\uff0c\u4f60\u8981\u662f\u4e0d\u7528\u8fd4\u56de\u503c\uff0c\u76f4\u63a5\u7528 execute \u65b9\u6cd5\u4e0d\u9999\u5417\uff1f<\/p>\n<p>\u53e6\u5916\u4e00\u4e2a\u662f\u56e0\u4e3a\u4f60\u8fd9\u6837\u5199\uff0c\u5982\u679c\u7ebf\u7a0b\u6c60\u91cc\u9762\u7684\u4efb\u52a1\u6267\u884c\u7684\u65f6\u5019\u51fa\u5f02\u5e38\u4e86\uff0c\u4f1a\u628a\u5f02\u5e38\u5c01\u88c5\u5230 Future \u91cc\u9762\u53bb\uff0c\u800c\u4f60\u53c8\u4e0d\u5173\u5fc3 Future\uff0c\u76f8\u5f53\u4e8e\u628a\u5f02\u5e38\u7ed9\u541e\u4e86\uff0c\u6392\u67e5\u95ee\u9898\u7684\u65f6\u5019\u4f60\u5c31\u54ed\u53bb\u5427\u3002<\/p>\n<p>\u8fd9\u4e9b\u90fd\u662f\u7f16\u7801\u8fc7\u7a0b\u4e2d\u7684\u4e00\u4e9b\u5c0f\u5751\u548c\u5c0f\u6ce8\u610f\u70b9\u3002<\/p>\n<h2>\u53cd\u8f6c<\/h2>\n<p>\u8fd9\u4e00\u5c0f\u8282\u7684\u9898\u76ee\u4e3a\u4ec0\u4e48\u8981\u53eb\u53cd\u8f6c\uff1f<\/p>\n<p>\u56e0\u4e3a\u4ee5\u4e0a\u7684\u5185\u5bb9\uff0c\u9664\u4e86\u6280\u672f\u539f\u7406\u662f\u771f\u7684\uff0c\u6211\u94fa\u57ab\u7684\u6240\u6709\u548c\u80cc\u666f\u76f8\u5173\u7684\u4e1c\u897f\uff0c\u5168\u90e8\u90fd\u662f\u5047\u7684\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279556\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u6574\u7bc7\u6587\u7ae0\u4ece\u7b2c\u4e8c\u53e5\u5f00\u59cb\u5c31\u662f\u5047\u7684\uff0c\u6211\u6839\u672c\u5c31\u6ca1\u6709\u9047\u5230\u8fc7\u8fd9\u6837\u7684\u4e00\u4e2a\u751f\u4ea7\u95ee\u9898\uff0c\u4e5f\u8c08\u4e0d\u4e0a\u627c\u6740\u5728\u6447\u7bee\u91cc\uff0c\u66f4\u8c08\u4e0d\u4e0a\u662f\u6211\u53bb\u89e3\u51b3\u7684\u4e86\u3002<\/p>\n<p>\u4f46\u662f\u6211\u5728\u5f00\u59cb\u7684\u65f6\u5019\u8bf4\u4e86\u8fd9\u6837\u4e00\u53e5\u8bdd\uff0c\u4e5f\u662f\u5168\u6587\u552f\u4e00\u4e00\u53e5\u52a0\u7c97\u7684\u8bdd\uff1a<\/p>\n<blockquote><p>\u867d\u7136\u73b0\u5728\u4e0d\u662f\u4f60\u7684\uff0c\u4f46\u662f\u4f60\u770b\u5b8c\u4e4b\u540e\u5c31\u662f\u4f60\u7684\u4e86\uff0c\u4f60\u660e\u767d\u6211\u610f\u601d\u5427\uff1f<\/p><\/blockquote>\n<p>\u6240\u4ee5\u8fd9\u4e2a\u80cc\u666f\u5176\u5b9e\u6211\u524d\u51e0\u5929\u770b\u5230\u4e86\u201c\u4e25\u9009\u6280\u672f\u201d\u53d1\u5e03\u7684\u8fd9\u7bc7\u6587\u7ae0<a href=\"https:\/\/link.segmentfault.com\/?enc=SrYkrcrlqq3v%2BsOAwqUKFg%3D%3D.LMKfoaFcH94umhvWFgGic4jkrO9vb2RU%2FCGJk3AWY%2BnG7AnE5QNVdXM19CRZ5eWMIk4%2F%2BRx8tJnIk2VjscKbRw%3D%3D\" rel=\"nofollow\">\u300a\u4e25\u9009\u5e93\u5b58\u7a33\u5b9a\u6027\u6cbb\u7406\u7cfb\u5217\uff1a\u4e00\u4e2a\u7ebf\u7a0b\u6c60\u62d2\u7edd\u7b56\u7565\u5f15\u53d1\u7684\u8840\u6848\u300b<\/a>\u3002<\/p>\n<p>\u770b\u5b8c\u4ed6\u4eec\u7684\u8fd9\u7bc7\u6587\u7ae0\u4e4b\u540e\uff0c\u6211\u60f3\u8d77\u4e86\u6211\u4e4b\u524d\u5199\u8fc7\u7684\u8fd9\u7bc7\u6587\u7ae0\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=QzQe5VoC%2BQLW0zIyRprhFw%3D%3D.3PobbslO9pHdNRVDRafIrs6ZemvVU7oB0IKyldzj4fJ0JnPPiGNEA2kQ6TT0uJkQsHxUffdIpi4DcutCgN9afw%3D%3D\" rel=\"nofollow\">\u300a\u770b\u8d77\u6765\u662f\u7ebf\u7a0b\u6c60\u7684BUG\uff0c\u4f46\u662f\u6211\u8ba4\u4e3a\u662f\u6e90\u7801\u8bbe\u8ba1\u4e0d\u5408\u7406\u3002\u300b<\/a><\/p>\n<p>\u6211\u5199\u7684\u8fd9\u7bc7\u5c31\u662f\u5355\u7eaf\u4ece\u6280\u672f\u89d2\u5ea6\u53bb\u89e3\u6790\u7684\u8fd9\u4e2a\u95ee\u9898\uff0c\u800c\u201c\u4e25\u9009\u6280\u672f\u201d\u5219\u662f\u4ece\u771f\u5b9e\u573a\u666f\u51fa\u53d1\uff0c\u5c42\u5c42\u5265\u8327\uff0c\u62b5\u8fbe\u4e86\u95ee\u9898\u7684\u6838\u5fc3\u3002<\/p>\n<p>\u4f46\u662f\u8fd9\u4e24\u7bc7\u6587\u7ae0\u9047\u5230\u7684\u95ee\u9898\u7684\u6838\u5fc3\u539f\u56e0\u5176\u5b9e\u662f\u4e00\u6a21\u4e00\u6837\u7684\u3002<\/p>\n<p>\u6211\u5728\u6211\u7684\u6587\u7ae0\u4e2d\u7684\u6700\u540e\u5c31\u6709\u8fd9\u6837\u4e00\u6bb5\u8bdd\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279557\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u5de7\u4e86\uff0c\u8fd9\u4e0d\u662f\u548c\u201c\u4e25\u9009\u6280\u672f\u201d\u91cc\u9762\u8fd9\u53e5\u8bdd\u9065\u76f8\u547c\u5e94\u8d77\u6765\u4e86\u5417\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043279558\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u5728\u6211\u53cd\u590d\u9605\u8bfb\u4e86\u4ed6\u4eec\u7684\u6587\u7ae0\uff0c\u4e86\u89e3\u5230\u4e86\u80cc\u666f\u548c\u539f\u56e0\u4e4b\u540e\uff0c\u6211\u6da6\u8272\u4e86\u4e00\u4e0b\uff0c\u5199\u4e86\u8fd9\u7bc7\u6587\u7ae0\u6765\u201c\u9a97\u201d\u4f60\u3002<\/p>\n<p>\u5982\u679c\u4f60\u6709\u90a3\u4e48\u51e0\u4e2a\u77ac\u95f4\u88ab\u6211\u201c\u9a97\u201d\u5230\u4e86\uff0c\u90a3\u4e48\u6211\u95ee\u4f60\u4e00\u4e2a\u95ee\u9898\uff1a\u5047\u8bbe\u4f60\u662f\u9762\u8bd5\u5b98\uff0c\u4f60\u95ee\u6211\u5de5\u4f5c\u4e2d\u6709\u6ca1\u6709\u9047\u5230\u8fc7\u6bd4\u8f83\u68d8\u624b\u7684\u95ee\u9898\uff1f<\/p>\n<p>\u800c\u6211\u662f\u4e00\u4e2a\u53ea\u6709\u4e09\u5e74\u5de5\u4f5c\u7ecf\u9a8c\u7684\u6c42\u804c\u8005\u3002<\/p>\n<p>\u6211\u7528\u8fd9\u7bc7\u6587\u7ae0\u4e2d\u6211\u5047\u60f3\u51fa\u6765\u7684\u751f\u4ea7\u95ee\u9898\u5904\u7406\u8fc7\u7a0b\uff0c\u5e76\u8f85\u4ee5\u6280\u672f\u7ec6\u8282\uff0c\u4f60\u80fd\u770b\u51fa\u6765\u8fd9\u662f\u6211\u201c\u5305\u88c5\u201d\u7684\u5417\uff1f<\/p>\n<p>\u7136\u540e\u5728\u63cf\u8ff0\u5b8c\u4e8b\u4ef6\u4e4b\u540e\uff0c\u518d\u4f53\u73b0\u4e00\u4e0b\u5bf9\u4e8e\u4e8b\u4ef6\u7684\u590d\u76d8\uff0c\u53ef\u4ee5\u8bf4\u4e00\u4e0b\u57fa\u4e8e\u8fd9\u4e2a\u4e8b\u60c5\uff0c\u540e\u9762\u81ea\u5df1\u5bf9\u76d1\u63a7\u5c42\u9762\u8fdb\u884c\u4e86\u4e30\u5bcc\uff0c\u6bd4\u5982\u63a5\u53e3\u8d85\u65f6\u7387\u76d1\u63a7\u3001GC \u5bfc\u81f4\u7684 STW \u65f6\u95f4\u76d1\u63a7\u5565\u7684\u3002\u7136\u540e\u4e5f\u5728\u516c\u53f8\u5185\u5f62\u6210\u4e86\u201c\u7ecf\u9a8c\u6559\u8bad\u201d\u6587\u6863\uff0c\u4e3b\u52a8\u540c\u6b65\u7ed9\u4e86\u5176\u4ed6\u7684\u540c\u4e8b\uff0c\u4ee5\u9632\u53cd\u590d\u8e29\u5751\uff0c\u5df4\u62c9\u5df4\u62c9\u5df4\u62c9&#8230;<\/p>\n<p>\u53cd\u6b63\u5427\uff0c\u4ee5\u540e\u770b\u5230\u81ea\u5df1\u89c9\u5f97\u597d\u7684\u6848\u4f8b\uff0c\u4e0d\u8981\u770b\u5b8c\u4e4b\u540e\u5c31\u5b8c\u4e86\uff0c\u591a\u60f3\u60f3\u600e\u4e48\u5b66\u4e00\u5b66\uff0c\u5305\u88c5\u6210\u81ea\u5df1\u7684\u4e1c\u897f\u3002<\/p>\n<p>\u8fd9\u6ce2\u5305\u88c5\uff0c\u5c5e\u4e8e\u624b\u6478\u624b\u6559\u5b66\u4e86\u5427\uff1f<\/p>\n<p>\u6c42\u4e2a\u8d5e\uff0c\u4e0d\u8fc7\u5206\u5427\uff1f<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000043279521\">https:\/\/segmentfault.com\/a\/1190000043279521<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f60\u597d\u5440\uff0c\u662f\u6b6a\u6b6a\u3002 \u524d\u51e0\u5929\uff0c\u5c31\u5728\u5927\u5bb6\u8fd8\u6c89\u6d78\u5728\u7b49\u5f85\u6625\u8282\u5230\u6765\u7684\u559c\u60a6\u6c1b\u56f4\u7684\u65f6\u5019\uff0c\u5728\u4e00\u4e2a\u6838\u5fc3\u94fe\u8def\u4e0a\u7684\u6838\u5fc3\u7cfb\u7edf\u4e2d\uff0c\u6211\u8e29\u5230\u4e00 [&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-10007053","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\/10007053","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=10007053"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10007053\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10007053"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10007053"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10007053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}