{"id":37695,"date":"2023-12-11T14:42:15","date_gmt":"2023-12-11T06:42:15","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=37695"},"modified":"2023-12-11T14:42:15","modified_gmt":"2023-12-11T06:42:15","slug":"%e5%88%9b%e5%bb%ba%e7%ba%bf%e7%a8%8b%e6%b1%a0%e6%9c%89%e5%93%aa%e5%87%a0%e7%a7%8d%e6%96%b9%e5%bc%8f%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/12\/11\/%e5%88%9b%e5%bb%ba%e7%ba%bf%e7%a8%8b%e6%b1%a0%e6%9c%89%e5%93%aa%e5%87%a0%e7%a7%8d%e6%96%b9%e5%bc%8f%ef%bc%9f\/","title":{"rendered":"\u521b\u5efa\u7ebf\u7a0b\u6c60\u6709\u54ea\u51e0\u79cd\u65b9\u5f0f\uff1f"},"content":{"rendered":"<p>&#8220;`<b>\u7ebf\u7a0b\u6c60\u521b\u5efa\u6709\u4e03\u79cd\u65b9\u5f0f\uff0c\u6700\u6838\u5fc3\u7684\u662f\u6700\u540e\u4e00\u79cd\uff1a<\/b><\/p>\n<p>&lt;b&gt;1. newSingleThreadExecutor()&lt;\/b&gt;\uff1a\u5b83\u7684\u7279\u70b9\u5728\u4e8e\u5de5\u4f5c\u7ebf\u7a0b\u6570\u76ee\u88ab\u9650\u5236\u4e3a 1\uff0c\u64cd\u4f5c\u4e00\u4e2a\u65e0\u754c\u7684\u5de5\u4f5c\u961f\u5217\uff0c\u6240\u4ee5\u5b83\u4fdd\u8bc1\u4e86\u6240\u6709\u4efb\u52a1\u7684\u90fd\u662f\u88ab\u987a\u5e8f\u6267\u884c\uff0c\u6700\u591a\u4f1a\u6709\u4e00\u4e2a\u4efb\u52a1\u5904\u4e8e\u6d3b\u52a8\u72b6\u6001\uff0c\u5e76\u4e14\u4e0d\u5141\u8bb8\u4f7f\u7528\u8005\u6539\u52a8\u7ebf\u7a0b\u6c60\u5b9e\u4f8b\uff0c\u56e0\u6b64\u53ef\u4ee5\u907f\u514d\u5176\u6539\u53d8\u7ebf\u7a0b\u6570\u76ee\uff1b<\/p>\n<p>&lt;b&gt;2. newCachedThreadPool()&lt;\/b&gt;\uff1a\u5b83\u662f\u4e00\u79cd\u7528\u6765\u5904\u7406\u5927\u91cf\u77ed\u65f6\u95f4\u5de5\u4f5c\u4efb\u52a1\u7684\u7ebf\u7a0b\u6c60\uff0c\u5177\u6709\u51e0\u4e2a\u9c9c\u660e\u7279\u70b9\uff1a\u5b83\u4f1a\u8bd5\u56fe\u7f13\u5b58\u7ebf\u7a0b\u5e76\u91cd\u7528\uff0c\u5f53\u65e0\u7f13\u5b58\u7ebf\u7a0b\u53ef\u7528\u65f6\uff0c\u5c31\u4f1a\u521b\u5efa\u65b0\u7684\u5de5\u4f5c\u7ebf\u7a0b\uff1b\u5982\u679c\u7ebf\u7a0b\u95f2\u7f6e\u7684\u65f6\u95f4\u8d85\u8fc7 60 \u79d2\uff0c\u5219\u88ab\u7ec8\u6b62\u5e76\u79fb\u51fa\u7f13\u5b58\uff1b\u957f\u65f6\u95f4\u95f2\u7f6e\u65f6\uff0c\u8fd9\u79cd\u7ebf\u7a0b\u6c60\uff0c\u4e0d\u4f1a\u6d88\u8017\u4ec0\u4e48\u8d44\u6e90\u3002\u5176\u5185\u90e8\u4f7f\u7528 SynchronousQueue \u4f5c\u4e3a\u5de5\u4f5c\u961f\u5217\uff1b<\/p>\n<p>&lt;b&gt;3. newFixedThreadPool(int nThreads&lt;\/b&gt;)\uff1a\u91cd\u7528\u6307\u5b9a\u6570\u76ee\uff08nThreads\uff09\u7684\u7ebf\u7a0b\uff0c\u5176\u80cc\u540e\u4f7f\u7528\u7684\u662f\u65e0\u754c\u7684\u5de5\u4f5c\u961f\u5217\uff0c\u4efb\u4f55\u65f6\u5019\u6700\u591a\u6709 nThreads \u4e2a\u5de5\u4f5c\u7ebf\u7a0b\u662f\u6d3b\u52a8\u7684\u3002\u8fd9\u610f\u5473\u7740\uff0c\u5982\u679c\u4efb\u52a1\u6570\u91cf\u8d85\u8fc7\u4e86\u6d3b\u52a8\u961f\u5217\u6570\u76ee\uff0c\u5c06\u5728\u5de5\u4f5c\u961f\u5217\u4e2d\u7b49\u5f85\u7a7a\u95f2\u7ebf\u7a0b\u51fa\u73b0\uff1b\u5982\u679c\u6709\u5de5\u4f5c\u7ebf\u7a0b\u9000\u51fa\uff0c\u5c06\u4f1a\u6709\u65b0\u7684\u5de5\u4f5c\u7ebf\u7a0b\u88ab\u521b\u5efa\uff0c\u4ee5\u8865\u8db3\u6307\u5b9a\u7684\u6570\u76ee nThreads\uff1b<\/p>\n<p>&lt;b&gt;4. newSingleThreadScheduledExecutor()&lt;\/b&gt;\uff1a\u521b\u5efa\u5355\u7ebf\u7a0b\u6c60\uff0c\u8fd4\u56de ScheduledExecutorService\uff0c\u53ef\u4ee5\u8fdb\u884c\u5b9a\u65f6\u6216\u5468\u671f\u6027\u7684\u5de5\u4f5c\u8c03\u5ea6\uff1b<\/p>\n<p>&lt;b&gt;5. newScheduledThreadPool(int corePoolSize)&lt;\/b&gt;\uff1a\u548cnewSingleThreadScheduledExecutor()\u7c7b\u4f3c\uff0c\u521b\u5efa\u7684\u662f\u4e2a ScheduledExecutorService\uff0c\u53ef\u4ee5\u8fdb\u884c\u5b9a\u65f6\u6216\u5468\u671f\u6027\u7684\u5de5\u4f5c\u8c03\u5ea6\uff0c\u533a\u522b\u5728\u4e8e\u5355\u4e00\u5de5\u4f5c\u7ebf\u7a0b\u8fd8\u662f\u591a\u4e2a\u5de5\u4f5c\u7ebf\u7a0b\uff1b<\/p>\n<p>&lt;b&gt;6. newWorkStealingPool(int parallelism)&lt;\/b&gt;\uff1a\u8fd9\u662f\u4e00\u4e2a\u7ecf\u5e38\u88ab\u4eba\u5ffd\u7565\u7684\u7ebf\u7a0b\u6c60\uff0cJava 8 \u624d\u52a0\u5165\u8fd9\u4e2a\u521b\u5efa\u65b9\u6cd5\uff0c\u5176\u5185\u90e8\u4f1a\u6784\u5efaForkJoinPool\uff0c\u5229\u7528Work-Stealing\u7b97\u6cd5\uff0c\u5e76\u884c\u5730\u5904\u7406\u4efb\u52a1\uff0c\u4e0d\u4fdd\u8bc1\u5904\u7406\u987a\u5e8f\uff1b<\/p>\n<p>&lt;b&gt;7. ThreadPoolExecutor()&lt;\/b&gt;\uff1a\u662f\u6700\u539f\u59cb\u7684\u7ebf\u7a0b\u6c60\u521b\u5efa\uff0c\u4e0a\u97621-3\u521b\u5efa\u65b9\u5f0f\u90fd\u662f\u5bf9ThreadPoolExecutor\u7684\u5c01\u88c5\u3002<\/p>\n<p>&#8220;`<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;`\u7ebf\u7a0b\u6c60\u521b\u5efa\u6709\u4e03\u79cd\u65b9\u5f0f\uff0c\u6700\u6838\u5fc3\u7684\u662f\u6700\u540e\u4e00\u79cd\uff1a &lt;b&gt;1. newSingleThre [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-37695","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/37695","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=37695"}],"version-history":[{"count":1,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/37695\/revisions"}],"predecessor-version":[{"id":37696,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/37695\/revisions\/37696"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=37695"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=37695"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=37695"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}