{"id":3982,"date":"2025-07-28T20:59:38","date_gmt":"2025-07-28T12:59:38","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=3982"},"modified":"2025-07-28T20:59:38","modified_gmt":"2025-07-28T12:59:38","slug":"java%e5%ae%98%e6%96%b9%e6%8f%90%e4%be%9b%e4%ba%86%e5%93%aa%e5%87%a0%e7%a7%8d%e7%ba%bf%e7%a8%8b%e6%b1%a0%ef%bc%8c%e5%88%86%e5%88%ab%e6%9c%89%e4%bb%80%e4%b9%88%e7%89%b9%e7%82%b9%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2025\/07\/28\/java%e5%ae%98%e6%96%b9%e6%8f%90%e4%be%9b%e4%ba%86%e5%93%aa%e5%87%a0%e7%a7%8d%e7%ba%bf%e7%a8%8b%e6%b1%a0%ef%bc%8c%e5%88%86%e5%88%ab%e6%9c%89%e4%bb%80%e4%b9%88%e7%89%b9%e7%82%b9%ef%bc%9f\/","title":{"rendered":"Java\u5b98\u65b9\u63d0\u4f9b\u4e86\u54ea\u51e0\u79cd\u7ebf\u7a0b\u6c60\uff0c\u5206\u522b\u6709\u4ec0\u4e48\u7279\u70b9\uff1f"},"content":{"rendered":"\n<p>Java \u5b98\u65b9\u63d0\u4f9b\u4e86\u51e0\u79cd\u5e38\u7528\u7684\u7ebf\u7a0b\u6c60\u5b9e\u73b0\uff0c\u4e3b\u8981\u901a\u8fc7 <code>java.util.concurrent.Executors<\/code> \u5de5\u5382\u7c7b\u6765\u521b\u5efa\u3002\u5b83\u4eec\u5404\u81ea\u9488\u5bf9\u4e0d\u540c\u7684\u573a\u666f\u4f18\u5316\uff0c\u8bbe\u8ba1\u7406\u5ff5\u548c\u6027\u80fd\u7279\u70b9\u5404\u5f02\u3002\u4e0b\u9762\u6211\u8be6\u7ec6\u5217\u4e3e\u5e76\u8bf4\u660e\u5b83\u4eec\u7684\u7279\u70b9\uff1a<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001Java \u5b98\u65b9\u63d0\u4f9b\u7684\u7ebf\u7a0b\u6c60\u7c7b\u578b\u53ca\u7279\u70b9<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7ebf\u7a0b\u6c60\u7c7b\u578b<\/th><th>\u521b\u5efa\u65b9\u6cd5<\/th><th>\u7ebf\u7a0b\u6570\u91cf\u63a7\u5236<\/th><th>\u4efb\u52a1\u6392\u961f\u7b56\u7565<\/th><th>\u9002\u7528\u573a\u666f<\/th><\/tr><\/thead><tbody><tr><td><strong>FixedThreadPool\uff08\u56fa\u5b9a\u7ebf\u7a0b\u6c60\uff09<\/strong><\/td><td><code>Executors.newFixedThreadPool(int nThreads)<\/code><\/td><td>\u56fa\u5b9a\u5927\u5c0f\u7ebf\u7a0b\u6c60\uff0c\u7ebf\u7a0b\u6570\u6052\u5b9a\u4e3a nThreads<\/td><td>\u4f7f\u7528\u65e0\u754c\u961f\u5217\uff08<code>LinkedBlockingQueue<\/code>\uff09\u6392\u961f<\/td><td>\u9002\u5408\u8d1f\u8f7d\u8f83\u91cd\u4e14\u4efb\u52a1\u8f83\u591a\u7684\u7a33\u5b9a\u7cfb\u7edf\uff0c\u907f\u514d\u9891\u7e41\u521b\u5efa\u9500\u6bc1\u7ebf\u7a0b<\/td><\/tr><tr><td><strong>CachedThreadPool\uff08\u7f13\u5b58\u7ebf\u7a0b\u6c60\uff09<\/strong><\/td><td><code>Executors.newCachedThreadPool()<\/code><\/td><td>\u7ebf\u7a0b\u6570\u91cf\u4e0d\u56fa\u5b9a\uff0c\u6309\u9700\u521b\u5efa\uff0c\u6700\u5927\u51e0\u4e4e\u65e0\u9650<\/td><td>\u4f7f\u7528\u65e0\u754c\u961f\u5217\uff08<code>SynchronousQueue<\/code>\uff09\uff0c\u4efb\u52a1\u76f4\u63a5\u4ea4\u7ed9\u7a7a\u95f2\u7ebf\u7a0b<\/td><td>\u9002\u5408\u6267\u884c\u5927\u91cf\u77ed\u751f\u547d\u5468\u671f\u5f02\u6b65\u4efb\u52a1\uff0c\u7ebf\u7a0b\u590d\u7528\u7387\u9ad8<\/td><\/tr><tr><td><strong>SingleThreadExecutor\uff08\u5355\u7ebf\u7a0b\u6c60\uff09<\/strong><\/td><td><code>Executors.newSingleThreadExecutor()<\/code><\/td><td>\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b<\/td><td>\u4f7f\u7528\u65e0\u754c\u961f\u5217\uff08<code>LinkedBlockingQueue<\/code>\uff09\u6392\u961f<\/td><td>\u9002\u5408\u9700\u8981\u987a\u5e8f\u6267\u884c\u4efb\u52a1\u4e14\u4fdd\u8bc1\u7ebf\u7a0b\u5b89\u5168\u7684\u573a\u666f<\/td><\/tr><tr><td><strong>ScheduledThreadPool\uff08\u5b9a\u65f6\u7ebf\u7a0b\u6c60\uff09<\/strong><\/td><td><code>Executors.newScheduledThreadPool(int corePoolSize)<\/code><\/td><td>\u56fa\u5b9a\u6838\u5fc3\u7ebf\u7a0b\u6570\uff0c\u53ef\u5468\u671f\u6267\u884c\u4efb\u52a1<\/td><td>\u4f7f\u7528\u5ef6\u8fdf\u961f\u5217\uff08<code>DelayedWorkQueue<\/code>\uff09<\/td><td>\u9002\u5408\u6267\u884c\u5b9a\u65f6\u4efb\u52a1\u548c\u5468\u671f\u4efb\u52a1<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">1. FixedThreadPool<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7ebf\u7a0b\u6570\u91cf\u56fa\u5b9a<\/strong>\uff0c\u5982\u679c\u7ebf\u7a0b\u90fd\u5728\u5fd9\uff0c\u4efb\u52a1\u4f1a\u88ab\u653e\u5165\u65e0\u754c\u961f\u5217\u7b49\u5f85\u3002<\/li>\n\n\n\n<li>\u7ebf\u7a0b\u521b\u5efa\u4e00\u6b21\u540e\u91cd\u590d\u5229\u7528\uff0c\u907f\u514d\u9891\u7e41\u521b\u5efa\u9500\u6bc1\u5f00\u9500\u3002<\/li>\n\n\n\n<li>\u7f3a\u70b9\uff1a\u4efb\u52a1\u79ef\u538b\u53ef\u80fd\u5bfc\u81f4\u5185\u5b58\u5360\u7528\u5347\u9ad8\uff0c\u9002\u5408\u4efb\u52a1\u6267\u884c\u65f6\u95f4\u76f8\u5bf9\u5747\u5300\u7684\u573a\u666f\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">2. CachedThreadPool<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7ebf\u7a0b\u6570\u91cf\u53ef\u4f38\u7f29<\/strong>\uff0c\u9ed8\u8ba4\u7a7a\u95f2\u7ebf\u7a0b\u8d85\u8fc7 60 \u79d2\u4f1a\u88ab\u56de\u6536\u3002<\/li>\n\n\n\n<li>\u4f7f\u7528 <code>SynchronousQueue<\/code> \u4f5c\u4e3a\u4efb\u52a1\u961f\u5217\uff0c\u76f4\u63a5\u628a\u4efb\u52a1\u4ea4\u7ed9\u7a7a\u95f2\u7ebf\u7a0b\uff0c\u4e0d\u5b58\u50a8\u4efb\u52a1\u3002<\/li>\n\n\n\n<li>\u9002\u5408\u6267\u884c\u5927\u91cf\u5f02\u6b65\u3001\u77ed\u65f6\u95f4\u3001\u8f7b\u91cf\u7ea7\u4efb\u52a1\u3002<\/li>\n\n\n\n<li>\u98ce\u9669\uff1a\u7ebf\u7a0b\u6570\u53ef\u80fd\u66b4\u6da8\uff0c\u5bfc\u81f4\u8d44\u6e90\u8017\u5c3d\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">3. SingleThreadExecutor<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5355\u7ebf\u7a0b\u987a\u5e8f\u6267\u884c<\/strong>\uff0c\u4fdd\u8bc1\u4efb\u52a1\u6267\u884c\u987a\u5e8f\u3002<\/li>\n\n\n\n<li>\u5b9e\u9645\u4e0a\u662f\u5927\u5c0f\u4e3a1\u7684 FixedThreadPool\uff0c\u7ebf\u7a0b\u5f02\u5e38\u7ec8\u6b62\u4f1a\u81ea\u52a8\u91cd\u5efa\u3002<\/li>\n\n\n\n<li>\u9002\u5408\u9700\u8981\u5355\u7ebf\u7a0b\u73af\u5883\u4fdd\u8bc1\u6570\u636e\u4e00\u81f4\u6027\u7684\u573a\u666f\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">4. ScheduledThreadPool<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u7528\u4e8e<strong>\u5b9a\u65f6\u8c03\u5ea6<\/strong>\u548c<strong>\u5468\u671f\u6267\u884c<\/strong>\u4efb\u52a1\u3002<\/li>\n\n\n\n<li>\u63d0\u4f9b\u7c7b\u4f3c <code>Timer<\/code> \u7684\u529f\u80fd\uff0c\u4f46\u6bd4 <code>Timer<\/code> \u66f4\u5f3a\u5927\u548c\u7075\u6d3b\u3002<\/li>\n\n\n\n<li>\u652f\u6301\u56fa\u5b9a\u5ef6\u8fdf\u3001\u56fa\u5b9a\u901f\u7387\u6267\u884c\u4efb\u52a1\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u989d\u5916\u8865\u5145\uff1a\u7ebf\u7a0b\u6c60\u5173\u952e\u53c2\u6570<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>corePoolSize<\/strong>\uff1a\u6838\u5fc3\u7ebf\u7a0b\u6570\uff0c\u7ebf\u7a0b\u6c60\u4fdd\u6301\u7684\u6700\u5c0f\u7ebf\u7a0b\u6570\u3002<\/li>\n\n\n\n<li><strong>maximumPoolSize<\/strong>\uff1a\u6700\u5927\u7ebf\u7a0b\u6570\u3002<\/li>\n\n\n\n<li><strong>keepAliveTime<\/strong>\uff1a\u975e\u6838\u5fc3\u7ebf\u7a0b\u95f2\u7f6e\u540e\u88ab\u56de\u6536\u7684\u65f6\u95f4\u3002<\/li>\n\n\n\n<li><strong>\u4efb\u52a1\u961f\u5217\u7c7b\u578b<\/strong>\uff1a\u76f4\u63a5\u5f71\u54cd\u7ebf\u7a0b\u6c60\u884c\u4e3a\uff08\u5982\u65e0\u754c\u961f\u5217\u3001\u6709\u9650\u961f\u5217\u3001SynchronousQueue\uff09\u3002<\/li>\n\n\n\n<li><strong>\u7ebf\u7a0b\u5de5\u5382<\/strong>\u3001<strong>\u62d2\u7edd\u7b56\u7565<\/strong>\uff1a\u53ef\u5b9a\u5236\u7ebf\u7a0b\u521b\u5efa\u548c\u4efb\u52a1\u62d2\u7edd\u884c\u4e3a\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001\u63a8\u8350\u8fdb\u4e00\u6b65\u9605\u8bfb\u548c\u6e90\u7801\u5206\u6790<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/util\/concurrent\/Executors.html\">Java\u5b98\u65b9\u6587\u6863 &#8211; Executors<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/util\/concurrent\/ThreadPoolExecutor.html\">Java\u5b98\u65b9\u6587\u6863 &#8211; ThreadPoolExecutor<\/a><\/li>\n\n\n\n<li>\u300aJava\u5e76\u53d1\u7f16\u7a0b\u5b9e\u6218\u300b\u7b2c 7 \u7ae0\u7ebf\u7a0b\u6c60\u8be6\u89e3<\/li>\n\n\n\n<li><a href=\"https:\/\/mp.weixin.qq.com\/s\/jjGxPn75tkFEEmmXhz2LhQ\">\u6df1\u5165\u6d45\u51faJava\u7ebf\u7a0b\u6c60 &#8211; \u516c\u4f17\u53f7\u6587\u7ae0<\/a><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u66f4\u591a\u8be6\u7ec6\u5185\u5bb9\u8bf7\u5173\u6ce8\u5176\u4ed6\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java \u5b98\u65b9\u63d0\u4f9b\u4e86\u51e0\u79cd\u5e38\u7528\u7684\u7ebf\u7a0b\u6c60\u5b9e\u73b0\uff0c\u4e3b\u8981\u901a\u8fc7 java.util.concurrent.Executor [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3983,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[68,86],"tags":[],"class_list":["post-3982","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","category-java-"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/3982","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=3982"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/3982\/revisions"}],"predecessor-version":[{"id":3984,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/3982\/revisions\/3984"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media\/3983"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=3982"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=3982"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=3982"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}