{"id":62914,"date":"2026-01-20T22:57:55","date_gmt":"2026-01-20T14:57:55","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/62914.html"},"modified":"2026-01-20T22:57:55","modified_gmt":"2026-01-20T14:57:55","slug":"java%e7%ba%bf%e7%a8%8b%e6%b1%a0%e6%a0%b8%e5%bf%83%e5%8e%9f%e7%90%86%e4%b8%8e%e5%ae%9e%e8%b7%b5%e9%81%bf%e5%9d%91%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/62914.html","title":{"rendered":"Java\u7ebf\u7a0b\u6c60\u6838\u5fc3\u539f\u7406\u4e0e\u5b9e\u8df5\u907f\u5751\u6307\u5357"},"content":{"rendered":"<p>\u5728Java\u5e76\u53d1\u7f16\u7a0b\u4e2d&#xff0c;\u7ebf\u7a0b\u6c60\u662f\u63d0\u5347\u7a0b\u5e8f\u6027\u80fd\u3001\u4f18\u5316\u8d44\u6e90\u5229\u7528\u7387\u7684\u6838\u5fc3\u7ec4\u4ef6\u3002\u65e0\u8bba\u662f\u65e5\u5e38\u5f00\u53d1\u4e2d\u7684\u63a5\u53e3\u4f18\u5316\u3001\u6279\u91cf\u4efb\u52a1\u5904\u7406&#xff0c;\u8fd8\u662f\u9ad8\u5e76\u53d1\u573a\u666f\u4e0b\u7684\u6d41\u91cf\u627f\u8f7d&#xff0c;\u5408\u7406\u4f7f\u7528\u7ebf\u7a0b\u6c60\u90fd\u80fd\u8d77\u5230\u4e8b\u534a\u529f\u500d\u7684\u6548\u679c\u3002\u4f46\u5982\u679c\u5bf9\u7ebf\u7a0b\u6c60\u7684\u539f\u7406\u7406\u89e3\u4e0d\u900f\u5f7b&#xff0c;\u968f\u610f\u914d\u7f6e\u53c2\u6570&#xff0c;\u53cd\u800c\u53ef\u80fd\u5f15\u53d1\u7ebf\u7a0b\u6cc4\u6f0f\u3001\u8d44\u6e90\u8017\u5c3d\u7b49\u4e25\u91cd\u95ee\u9898\u3002\u672c\u6587\u5c06\u4ece\u7ebf\u7a0b\u6c60\u7684\u6838\u5fc3\u539f\u7406\u51fa\u53d1&#xff0c;\u7ed3\u5408\u5b9e\u9645\u5f00\u53d1\u573a\u666f&#xff0c;\u68b3\u7406\u7ebf\u7a0b\u6c60\u7684\u6b63\u786e\u4f7f\u7528\u65b9\u5f0f\u4e0e\u5e38\u89c1\u5751\u70b9&#xff0c;\u5e2e\u52a9\u5f00\u53d1\u8005\u5c11\u8d70\u5f2f\u8def\u3002<\/p>\n<h2>\u4e00\u3001\u7ebf\u7a0b\u6c60\u6838\u5fc3\u539f\u7406&#xff1a;\u4e3a\u4ec0\u4e48\u9700\u8981\u7ebf\u7a0b\u6c60&#xff1f;<\/h2>\n<p>\u5728\u6ca1\u6709\u7ebf\u7a0b\u6c60\u7684\u60c5\u51b5\u4e0b&#xff0c;\u6bcf\u6b21\u521b\u5efa\u7ebf\u7a0b\u90fd\u9700\u8981\u5360\u7528\u7cfb\u7edf\u8d44\u6e90&#xff08;\u5982\u5185\u5b58\u3001CPU\u8c03\u5ea6\u65f6\u95f4&#xff09;&#xff0c;\u4e14\u7ebf\u7a0b\u6267\u884c\u5b8c\u4efb\u52a1\u540e\u4f1a\u88ab\u9500\u6bc1\u3002\u5982\u679c\u9891\u7e41\u521b\u5efa\u5927\u91cf\u7ebf\u7a0b&#xff0c;\u4f1a\u5bfc\u81f4\u7cfb\u7edf\u8d44\u6e90\u8fc7\u5ea6\u6d88\u8017&#xff0c;\u751a\u81f3\u51fa\u73b0OOM&#xff08;OutOfMemoryError&#xff09;\u3002\u800c\u7ebf\u7a0b\u6c60\u901a\u8fc7\u201c\u6c60\u5316\u6280\u672f\u201d&#xff0c;\u9884\u5148\u521b\u5efa\u4e00\u5b9a\u6570\u91cf\u7684\u7ebf\u7a0b&#xff0c;\u4efb\u52a1\u63d0\u4ea4\u65f6\u76f4\u63a5\u590d\u7528\u73b0\u6709\u7ebf\u7a0b&#xff0c;\u4efb\u52a1\u6267\u884c\u5b8c\u540e\u7ebf\u7a0b\u4e0d\u9500\u6bc1&#xff0c;\u800c\u662f\u8fd4\u56de\u7ebf\u7a0b\u6c60\u7b49\u5f85\u4e0b\u4e00\u4e2a\u4efb\u52a1&#xff0c;\u4ece\u800c\u5b9e\u73b0&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u51cf\u5c11\u7ebf\u7a0b\u521b\u5efa\u4e0e\u9500\u6bc1\u7684\u5f00\u9500&#xff0c;\u63d0\u5347\u7a0b\u5e8f\u54cd\u5e94\u901f\u5ea6&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u63a7\u5236\u5e76\u53d1\u7ebf\u7a0b\u6570\u91cf&#xff0c;\u907f\u514d\u56e0\u7ebf\u7a0b\u8fc7\u591a\u5bfc\u81f4\u7684CPU\u4e0a\u4e0b\u6587\u5207\u6362\u9891\u7e41&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u7edf\u4e00\u7ba1\u7406\u7ebf\u7a0b\u751f\u547d\u5468\u671f&#xff0c;\u4fbf\u4e8e\u4efb\u52a1\u8c03\u5ea6\u3001\u76d1\u63a7\u4e0e\u5f02\u5e38\u5904\u7406\u3002<\/p>\n<\/li>\n<\/ul>\n<h3>1.1 \u7ebf\u7a0b\u6c60\u6838\u5fc3\u53c2\u6570\u89e3\u6790<\/h3>\n<p>Java\u4e2d\u7ebf\u7a0b\u6c60\u7684\u6838\u5fc3\u5b9e\u73b0\u7c7b\u662fThreadPoolExecutor&#xff0c;\u5176\u6784\u9020\u65b9\u6cd5\u5305\u542b7\u4e2a\u6838\u5fc3\u53c2\u6570&#xff0c;\u7406\u89e3\u8fd9\u4e9b\u53c2\u6570\u662f\u6b63\u786e\u4f7f\u7528\u7ebf\u7a0b\u6c60\u7684\u57fa\u7840&#xff1a;<\/p>\n<p>public ThreadPoolExecutor(int corePoolSize,<br \/>\n                          int maximumPoolSize,<br \/>\n                          long keepAliveTime,<br \/>\n                          TimeUnit unit,<br \/>\n                          BlockingQueue&lt;Runnable&gt; workQueue,<br \/>\n                          ThreadFactory threadFactory,<br \/>\n                          RejectedExecutionHandler handler) {<br \/>\n    \/\/ \u6784\u9020\u903b\u8f91\u7701\u7565<br \/>\n}<\/p>\n<p>\u5404\u53c2\u6570\u542b\u4e49\u8be6\u89e3&#xff1a;<\/p>\n<li>\n<p>corePoolSize&#xff08;\u6838\u5fc3\u7ebf\u7a0b\u6570&#xff09;&#xff1a;\u7ebf\u7a0b\u6c60\u957f\u671f\u4fdd\u7559\u7684\u6838\u5fc3\u7ebf\u7a0b\u6570\u91cf&#xff0c;\u5373\u4f7f\u7ebf\u7a0b\u5904\u4e8e\u7a7a\u95f2\u72b6\u6001\u4e5f\u4e0d\u4f1a\u9500\u6bc1&#xff08;\u9664\u975e\u8bbe\u7f6e\u4e86allowCoreThreadTimeOut\u4e3atrue&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>maximumPoolSize&#xff08;\u6700\u5927\u7ebf\u7a0b\u6570&#xff09;&#xff1a;\u7ebf\u7a0b\u6c60\u53ef\u521b\u5efa\u7684\u6700\u5927\u7ebf\u7a0b\u6570\u91cf&#xff0c;\u5f53\u6838\u5fc3\u7ebf\u7a0b\u90fd\u5728\u5de5\u4f5c\u3001\u4efb\u52a1\u961f\u5217\u5df2\u6ee1\u65f6&#xff0c;\u4f1a\u521b\u5efa\u65b0\u7ebf\u7a0b\u76f4\u5230\u8fbe\u5230\u8be5\u6570\u91cf\u3002<\/p>\n<\/li>\n<li>\n<p>keepAliveTime&#xff08;\u7a7a\u95f2\u7ebf\u7a0b\u5b58\u6d3b\u65f6\u95f4&#xff09;&#xff1a;\u975e\u6838\u5fc3\u7ebf\u7a0b\u7a7a\u95f2\u540e\u7684\u6700\u5927\u5b58\u6d3b\u65f6\u95f4&#xff0c;\u8d85\u8fc7\u8be5\u65f6\u95f4\u672a\u63a5\u5230\u65b0\u4efb\u52a1\u5219\u88ab\u9500\u6bc1\u3002<\/p>\n<\/li>\n<li>\n<p>unit&#xff08;\u65f6\u95f4\u5355\u4f4d&#xff09;&#xff1a;keepAliveTime\u7684\u65f6\u95f4\u5355\u4f4d&#xff0c;\u5982TimeUnit.SECONDS\u3001TimeUnit.MILLISECONDS\u3002<\/p>\n<\/li>\n<li>\n<p>workQueue&#xff08;\u4efb\u52a1\u961f\u5217&#xff09;&#xff1a;\u7528\u4e8e\u5b58\u50a8\u7b49\u5f85\u6267\u884c\u7684\u4efb\u52a1&#xff0c;\u6838\u5fc3\u7ebf\u7a0b\u6ee1\u8d1f\u8377\u65f6&#xff0c;\u65b0\u4efb\u52a1\u4f1a\u5148\u8fdb\u5165\u961f\u5217\u7b49\u5f85&#xff0c;\u800c\u975e\u76f4\u63a5\u521b\u5efa\u65b0\u7ebf\u7a0b\u3002\u5e38\u7528\u5b9e\u73b0\u6709ArrayBlockingQueue\u3001LinkedBlockingQueue\u3001SynchronousQueue\u7b49\u3002<\/p>\n<\/li>\n<li>\n<p>threadFactory&#xff08;\u7ebf\u7a0b\u5de5\u5382&#xff09;&#xff1a;\u7528\u4e8e\u521b\u5efa\u7ebf\u7a0b\u7684\u5de5\u5382\u7c7b&#xff0c;\u53ef\u81ea\u5b9a\u4e49\u7ebf\u7a0b\u540d\u79f0\u3001\u4f18\u5148\u7ea7\u3001\u662f\u5426\u4e3a\u5b88\u62a4\u7ebf\u7a0b\u7b49&#xff0c;\u4fbf\u4e8e\u95ee\u9898\u6392\u67e5\u3002<\/p>\n<\/li>\n<li>\n<p>handler&#xff08;\u62d2\u7edd\u7b56\u7565&#xff09;&#xff1a;\u5f53\u7ebf\u7a0b\u6c60\u8fbe\u5230\u6700\u5927\u7ebf\u7a0b\u6570\u4e14\u4efb\u52a1\u961f\u5217\u5df2\u6ee1\u65f6&#xff0c;\u5bf9\u65b0\u63d0\u4ea4\u4efb\u52a1\u7684\u5904\u7406\u7b56\u7565\u3002JDK\u9ed8\u8ba4\u63d0\u4f9b4\u79cd\u7b56\u7565&#xff0c;\u4e5f\u53ef\u81ea\u5b9a\u4e49\u3002<\/p>\n<\/li>\n<h3>1.2 \u7ebf\u7a0b\u6c60\u5de5\u4f5c\u6d41\u7a0b<\/h3>\n<p>\u5f53\u63d0\u4ea4\u4e00\u4e2a\u65b0\u4efb\u52a1\u5230\u7ebf\u7a0b\u6c60\u65f6&#xff0c;\u7ebf\u7a0b\u6c60\u7684\u6267\u884c\u6d41\u7a0b\u5982\u4e0b&#xff1a;<\/p>\n<li>\n<p>\u5224\u65ad\u6838\u5fc3\u7ebf\u7a0b\u6c60\u662f\u5426\u5df2\u6ee1&#xff1f;\u82e5\u672a\u6ee1&#xff0c;\u521b\u5efa\u6838\u5fc3\u7ebf\u7a0b\u6267\u884c\u4efb\u52a1&#xff1b;\u82e5\u5df2\u6ee1&#xff0c;\u8fdb\u5165\u4e0b\u4e00\u6b65\u3002<\/p>\n<\/li>\n<li>\n<p>\u5224\u65ad\u4efb\u52a1\u961f\u5217\u662f\u5426\u5df2\u6ee1&#xff1f;\u82e5\u672a\u6ee1&#xff0c;\u5c06\u4efb\u52a1\u653e\u5165\u961f\u5217\u7b49\u5f85&#xff1b;\u82e5\u5df2\u6ee1&#xff0c;\u8fdb\u5165\u4e0b\u4e00\u6b65\u3002<\/p>\n<\/li>\n<li>\n<p>\u5224\u65ad\u7ebf\u7a0b\u6c60\u662f\u5426\u5df2\u8fbe\u5230\u6700\u5927\u7ebf\u7a0b\u6570&#xff1f;\u82e5\u672a\u8fbe\u5230&#xff0c;\u521b\u5efa\u975e\u6838\u5fc3\u7ebf\u7a0b\u6267\u884c\u4efb\u52a1&#xff1b;\u82e5\u5df2\u8fbe\u5230&#xff0c;\u89e6\u53d1\u62d2\u7edd\u7b56\u7565\u3002<\/p>\n<\/li>\n<p>\u6838\u5fc3\u8981\u70b9&#xff1a;\u7ebf\u7a0b\u6c60\u7684\u4efb\u52a1\u6267\u884c\u4f18\u5148\u7ea7\u4e3a\u300c\u6838\u5fc3\u7ebf\u7a0b &gt; \u4efb\u52a1\u961f\u5217 &gt; \u975e\u6838\u5fc3\u7ebf\u7a0b\u300d&#xff0c;\u53ea\u6709\u524d\u4e24\u8005\u90fd\u6ee1\u4e86&#xff0c;\u624d\u4f1a\u521b\u5efa\u975e\u6838\u5fc3\u7ebf\u7a0b\u3002<\/p>\n<h2>\u4e8c\u3001\u7ebf\u7a0b\u6c60\u5b9e\u8df5&#xff1a;\u5982\u4f55\u6b63\u786e\u914d\u7f6e\u4e0e\u4f7f\u7528&#xff1f;<\/h2>\n<p>\u7ebf\u7a0b\u6c60\u7684\u914d\u7f6e\u6ca1\u6709\u56fa\u5b9a\u6807\u51c6&#xff0c;\u9700\u7ed3\u5408\u4e1a\u52a1\u573a\u666f&#xff08;CPU\u5bc6\u96c6\u578b\/IO\u5bc6\u96c6\u578b&#xff09;\u3001\u7cfb\u7edf\u8d44\u6e90&#xff08;\u5185\u5b58\u3001CPU\u6838\u5fc3\u6570&#xff09;\u5408\u7406\u8c03\u6574\u3002\u4ee5\u4e0b\u662f\u5b9e\u8df5\u4e2d\u7684\u6838\u5fc3\u914d\u7f6e\u539f\u5219\u4e0e\u793a\u4f8b\u3002<\/p>\n<h3>2.1 \u6838\u5fc3\u53c2\u6570\u914d\u7f6e\u539f\u5219<\/h3>\n<p>\u6839\u636e\u4efb\u52a1\u7c7b\u578b\u533a\u5206\u914d\u7f6e&#xff1a;<\/p>\n<li>\n<p>CPU\u5bc6\u96c6\u578b\u4efb\u52a1&#xff1a;\u4efb\u52a1\u4e3b\u8981\u6d88\u8017CPU\u8d44\u6e90&#xff08;\u5982\u8ba1\u7b97\u3001\u6392\u5e8f&#xff09;&#xff0c;\u7ebf\u7a0b\u6570\u8fc7\u591a\u4f1a\u5bfc\u81f4CPU\u4e0a\u4e0b\u6587\u5207\u6362\u9891\u7e41&#xff0c;\u964d\u4f4e\u6548\u7387\u3002\u5efa\u8bae\u914d\u7f6e&#xff1a;\u6838\u5fc3\u7ebf\u7a0b\u6570 &#061; CPU\u6838\u5fc3\u6570 &#043; 1\u3002<\/p>\n<\/li>\n<li>\n<p>IO\u5bc6\u96c6\u578b\u4efb\u52a1&#xff1a;\u4efb\u52a1\u4e3b\u8981\u6d88\u8017IO\u8d44\u6e90&#xff08;\u5982\u6570\u636e\u5e93\u67e5\u8be2\u3001\u7f51\u7edc\u8bf7\u6c42&#xff09;&#xff0c;\u7ebf\u7a0b\u5927\u90e8\u5206\u65f6\u95f4\u5904\u4e8e\u7b49\u5f85\u72b6\u6001&#xff0c;\u53ef\u914d\u7f6e\u66f4\u591a\u7ebf\u7a0b\u63d0\u9ad8\u5229\u7528\u7387\u3002\u5efa\u8bae\u914d\u7f6e&#xff1a;\u6838\u5fc3\u7ebf\u7a0b\u6570 &#061; CPU\u6838\u5fc3\u6570 * 2 \u6216 CPU\u6838\u5fc3\u6570 * &#xff08;1 &#043; \u5e73\u5747\u7b49\u5f85\u65f6\u95f4\/\u5e73\u5747\u6267\u884c\u65f6\u95f4&#xff09;\u3002<\/p>\n<\/li>\n<p>\u8865\u5145&#xff1a;\u83b7\u53d6CPU\u6838\u5fc3\u6570\u7684\u65b9\u5f0f&#xff1a;<\/p>\n<p>Runtime.getRuntime().availableProcessors()<\/p>\n<h3>2.2 \u4efb\u52a1\u961f\u5217\u9009\u62e9<\/h3>\n<p>\u4e0d\u540c\u961f\u5217\u7684\u7279\u6027\u51b3\u5b9a\u4e86\u7ebf\u7a0b\u6c60\u7684\u4efb\u52a1\u8c03\u5ea6\u65b9\u5f0f&#xff0c;\u9700\u7ed3\u5408\u573a\u666f\u9009\u62e9&#xff1a;<\/p>\n<ul>\n<li>\n<p>ArrayBlockingQueue&#xff08;\u6709\u754c\u961f\u5217&#xff09;&#xff1a;\u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0&#xff0c;\u5bb9\u91cf\u56fa\u5b9a&#xff0c;\u80fd\u907f\u514d\u4efb\u52a1\u961f\u5217\u65e0\u9650\u589e\u957f\u5bfc\u81f4\u7684OOM&#xff0c;\u5efa\u8bae\u4f18\u5148\u4f7f\u7528\u3002\u9002\u7528\u4e8e\u5bf9\u7cfb\u7edf\u7a33\u5b9a\u6027\u8981\u6c42\u9ad8\u7684\u573a\u666f\u3002<\/p>\n<\/li>\n<li>\n<p>LinkedBlockingQueue&#xff08;\u65e0\u754c\u961f\u5217&#xff09;&#xff1a;\u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0&#xff0c;\u9ed8\u8ba4\u5bb9\u91cf\u4e3aInteger.MAX_VALUE&#xff08;\u76f8\u5f53\u4e8e\u65e0\u754c&#xff09;&#xff0c;\u5bb9\u6613\u5bfc\u81f4\u4efb\u52a1\u5806\u79ef\u8fc7\u591a\u5f15\u53d1OOM&#xff0c;\u9664\u975e\u80fd\u786e\u4fdd\u4efb\u52a1\u91cf\u53ef\u63a7&#xff0c;\u5426\u5219\u4e0d\u5efa\u8bae\u4f7f\u7528\u3002<\/p>\n<\/li>\n<li>\n<p>SynchronousQueue&#xff08;\u540c\u6b65\u961f\u5217&#xff09;&#xff1a;\u4e0d\u5b58\u50a8\u4efb\u52a1&#xff0c;\u63d0\u4ea4\u7684\u4efb\u52a1\u5fc5\u987b\u7acb\u5373\u88ab\u7ebf\u7a0b\u6267\u884c&#xff0c;\u5426\u5219\u89e6\u53d1\u62d2\u7edd\u7b56\u7565\u3002\u9002\u7528\u4e8e\u9700\u8981\u5feb\u901f\u54cd\u5e94\u3001\u4efb\u52a1\u91cf\u5927\u4f46\u8017\u65f6\u77ed\u7684\u573a\u666f&#xff08;\u5982Netty\u7684IO\u5904\u7406&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>PriorityBlockingQueue&#xff08;\u4f18\u5148\u7ea7\u961f\u5217&#xff09;&#xff1a;\u6309\u4efb\u52a1\u4f18\u5148\u7ea7\u6392\u5e8f\u6267\u884c&#xff0c;\u9002\u7528\u4e8e\u9700\u8981\u4f18\u5148\u5904\u7406\u6838\u5fc3\u4efb\u52a1\u7684\u573a\u666f&#xff08;\u5982\u8ba2\u5355\u652f\u4ed8\u4efb\u52a1\u4f18\u5148\u4e8e\u8ba2\u5355\u67e5\u8be2\u4efb\u52a1&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<h3>2.3 \u62d2\u7edd\u7b56\u7565\u9009\u62e9<\/h3>\n<p>JDK\u9ed8\u8ba4\u63d0\u4f9b4\u79cd\u62d2\u7edd\u7b56\u7565&#xff0c;\u5404\u6709\u9002\u7528\u573a\u666f&#xff1a;<\/p>\n<ul>\n<li>\n<p>AbortPolicy&#xff08;\u9ed8\u8ba4&#xff09;&#xff1a;\u76f4\u63a5\u629b\u51faRejectedExecutionException\u5f02\u5e38&#xff0c;\u4e2d\u65ad\u4efb\u52a1\u63d0\u4ea4\u3002\u9002\u7528\u4e8e\u4e0d\u5141\u8bb8\u4efb\u52a1\u4e22\u5931\u3001\u9700\u8981\u611f\u77e5\u5931\u8d25\u7684\u573a\u666f&#xff08;\u5982\u6838\u5fc3\u4e1a\u52a1\u4efb\u52a1&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>CallerRunsPolicy&#xff1a;\u7531\u63d0\u4ea4\u4efb\u52a1\u7684\u4e3b\u7ebf\u7a0b\u6267\u884c\u4efb\u52a1&#xff0c;\u964d\u4f4e\u65b0\u4efb\u52a1\u63d0\u4ea4\u901f\u5ea6&#xff0c;\u8d77\u5230\u201c\u9650\u6d41\u201d\u4f5c\u7528\u3002\u9002\u7528\u4e8e\u4efb\u52a1\u91cf\u6ce2\u52a8\u5927\u3001\u4e0d\u5141\u8bb8\u4efb\u52a1\u4e22\u5931\u7684\u975e\u6838\u5fc3\u573a\u666f\u3002<\/p>\n<\/li>\n<li>\n<p>DiscardPolicy&#xff1a;\u76f4\u63a5\u4e22\u5f03\u65b0\u4efb\u52a1&#xff0c;\u4e0d\u629b\u51fa\u5f02\u5e38\u3002\u9002\u7528\u4e8e\u4efb\u52a1\u65e0\u5173\u7d27\u8981\u3001\u5141\u8bb8\u4e22\u5931\u7684\u573a\u666f&#xff08;\u5982\u65e5\u5fd7\u6536\u96c6&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>DiscardOldestPolicy&#xff1a;\u4e22\u5f03\u4efb\u52a1\u961f\u5217\u4e2d\u6700\u65e7\u7684\u4efb\u52a1&#xff0c;\u7136\u540e\u63d0\u4ea4\u65b0\u4efb\u52a1\u3002\u9002\u7528\u4e8e\u4efb\u52a1\u6709\u65f6\u95f4\u5148\u540e\u987a\u5e8f\u3001\u65e7\u4efb\u52a1\u53ef\u8fc7\u671f\u7684\u573a\u666f\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u81ea\u5b9a\u4e49\u62d2\u7edd\u7b56\u7565\u793a\u4f8b&#xff08;\u5982\u5c06\u4efb\u52a1\u5b58\u5165Redis\u91cd\u8bd5&#xff09;&#xff1a;<\/p>\n<p>RejectedExecutionHandler customHandler &#061; (r, executor) -&gt; {<br \/>\n    \/\/ \u81ea\u5b9a\u4e49\u903b\u8f91&#xff1a;\u5982\u5b58\u5165\u6d88\u606f\u961f\u5217\u3001\u8bb0\u5f55\u65e5\u5fd7\u3001\u5b9a\u65f6\u91cd\u8bd5<br \/>\n    log.warn(&#034;\u7ebf\u7a0b\u6c60\u4efb\u52a1\u5df2\u6ee1&#xff0c;\u62d2\u7edd\u4efb\u52a1&#xff1a;{}&#034;, r);<br \/>\n    redisTemplate.opsForList().leftPush(&#034;threadPool_retry_tasks&#034;, JSON.toJSONString(r));<br \/>\n};<\/p>\n<h3>2.4 \u7ebf\u7a0b\u6c60\u521b\u5efa\u793a\u4f8b&#xff08;\u751f\u4ea7\u7ea7&#xff09;<\/h3>\n<p>\u907f\u514d\u4f7f\u7528Executors\u5de5\u5177\u7c7b\u521b\u5efa\u7ebf\u7a0b\u6c60&#xff08;\u5982newFixedThreadPool\u3001newCachedThreadPool&#xff09;&#xff0c;\u5176\u9ed8\u8ba4\u914d\u7f6e&#xff08;\u5982\u65e0\u754c\u961f\u5217&#xff09;\u6613\u5f15\u53d1OOM&#xff0c;\u5efa\u8bae\u76f4\u63a5\u4f7f\u7528ThreadPoolExecutor\u6784\u9020\u65b9\u6cd5&#xff0c;\u81ea\u5b9a\u4e49\u914d\u7f6e&#xff1a;<\/p>\n<p>import java.util.concurrent.*;<br \/>\nimport java.util.concurrent.atomic.AtomicInteger;<\/p>\n<p>public class ThreadPoolFactory {<\/p>\n<p>    \/\/ CPU\u6838\u5fc3\u6570<br \/>\n    private static final int CPU_CORES &#061; Runtime.getRuntime().availableProcessors();<\/p>\n<p>    \/\/ \u81ea\u5b9a\u4e49\u7ebf\u7a0b\u5de5\u5382<br \/>\n    private static final ThreadFactory CUSTOM_THREAD_FACTORY &#061; new ThreadFactory() {<br \/>\n        private final AtomicInteger threadNum &#061; new AtomicInteger(1);<\/p>\n<p>        &#064;Override<br \/>\n        public Thread newThread(Runnable r) {<br \/>\n            Thread thread &#061; new Thread(r);<br \/>\n            thread.setName(&#034;biz-thread-pool-&#034; &#043; threadNum.getAndIncrement());<br \/>\n            thread.setDaemon(false); \/\/ \u975e\u5b88\u62a4\u7ebf\u7a0b&#xff0c;\u786e\u4fdd\u4efb\u52a1\u6267\u884c\u5b8c<br \/>\n            thread.setPriority(Thread.NORM_PRIORITY); \/\/ \u6b63\u5e38\u4f18\u5148\u7ea7<br \/>\n            return thread;<br \/>\n        }<br \/>\n    };<\/p>\n<p>    \/\/ \u81ea\u5b9a\u4e49\u62d2\u7edd\u7b56\u7565<br \/>\n    private static final RejectedExecutionHandler CUSTOM_HANDLER &#061; (r, executor) -&gt; {<br \/>\n        \/\/ \u5b9e\u9645\u573a\u666f\u53ef\u66ff\u6362\u4e3a\u5b58\u5165\u6d88\u606f\u961f\u5217\u91cd\u8bd5<br \/>\n        throw new RejectedExecutionException(&#034;\u7ebf\u7a0b\u6c60\u7e41\u5fd9&#xff0c;\u4efb\u52a1\u62d2\u7edd&#xff1a;&#034; &#043; r.toString());<br \/>\n    };<\/p>\n<p>    \/\/ \u521b\u5efaIO\u5bc6\u96c6\u578b\u7ebf\u7a0b\u6c60<br \/>\n    public static ExecutorService createIoIntensiveThreadPool() {<br \/>\n        return new ThreadPoolExecutor(<br \/>\n                CPU_CORES * 2, \/\/ \u6838\u5fc3\u7ebf\u7a0b\u6570<br \/>\n                CPU_CORES * 4, \/\/ \u6700\u5927\u7ebf\u7a0b\u6570<br \/>\n                60L, \/\/ \u7a7a\u95f2\u7ebf\u7a0b\u5b58\u6d3b\u65f6\u95f4<br \/>\n                TimeUnit.SECONDS,<br \/>\n                new ArrayBlockingQueue&lt;&gt;(1024), \/\/ \u6709\u754c\u961f\u5217&#xff0c;\u5bb9\u91cf1024<br \/>\n                CUSTOM_THREAD_FACTORY,<br \/>\n                CUSTOM_HANDLER<br \/>\n        );<br \/>\n    }<\/p>\n<p>    \/\/ \u521b\u5efaCPU\u5bc6\u96c6\u578b\u7ebf\u7a0b\u6c60<br \/>\n    public static ExecutorService createCpuIntensiveThreadPool() {<br \/>\n        return new ThreadPoolExecutor(<br \/>\n                CPU_CORES &#043; 1, \/\/ \u6838\u5fc3\u7ebf\u7a0b\u6570<br \/>\n                CPU_CORES * 2, \/\/ \u6700\u5927\u7ebf\u7a0b\u6570<br \/>\n                60L,<br \/>\n                TimeUnit.SECONDS,<br \/>\n                new ArrayBlockingQueue&lt;&gt;(512),<br \/>\n                CUSTOM_THREAD_FACTORY,<br \/>\n                CUSTOM_HANDLER<br \/>\n        );<br \/>\n    }<br \/>\n}<\/p>\n<h2>\u4e09\u3001\u7ebf\u7a0b\u6c60\u907f\u5751\u6307\u5357&#xff1a;\u5e38\u89c1\u95ee\u9898\u4e0e\u89e3\u51b3\u65b9\u6848<\/h2>\n<p>\u5b9e\u9645\u5f00\u53d1\u4e2d&#xff0c;\u7ebf\u7a0b\u6c60\u7684\u4f7f\u7528\u5bb9\u6613\u51fa\u73b0\u5404\u7c7b\u95ee\u9898&#xff0c;\u4ee5\u4e0b\u662f\u9ad8\u9891\u5751\u70b9\u53ca\u89c4\u907f\u65b9\u6848\u3002<\/p>\n<h3>3.1 \u5751\u70b91&#xff1a;\u4f7f\u7528Executors\u5de5\u5177\u7c7b\u521b\u5efa\u7ebf\u7a0b\u6c60<\/h3>\n<p>\u95ee\u9898\u5206\u6790&#xff1a;Executors\u521b\u5efa\u7684\u7ebf\u7a0b\u6c60\u5b58\u5728\u9690\u85cf\u98ce\u9669&#xff1a;<\/p>\n<ul>\n<li>\n<p>newFixedThreadPool&#xff1a;\u4f7f\u7528LinkedBlockingQueue&#xff08;\u65e0\u754c\u961f\u5217&#xff09;&#xff0c;\u4efb\u52a1\u8fc7\u591a\u65f6\u4f1a\u5806\u79ef\u5bfc\u81f4OOM&#xff1b;<\/p>\n<\/li>\n<li>\n<p>newCachedThreadPool&#xff1a;\u6700\u5927\u7ebf\u7a0b\u6570\u4e3aInteger.MAX_VALUE&#xff0c;\u53ef\u521b\u5efa\u65e0\u9650\u591a\u7ebf\u7a0b&#xff0c;\u5bfc\u81f4CPU\u548c\u5185\u5b58\u8017\u5c3d&#xff1b;<\/p>\n<\/li>\n<li>\n<p>newScheduledThreadPool&#xff1a;\u9ed8\u8ba4\u4f7f\u7528\u65e0\u754c\u961f\u5217&#xff0c;\u540c\u6837\u5b58\u5728OOM\u98ce\u9669\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u89e3\u51b3\u65b9\u6848&#xff1a;\u653e\u5f03Executors&#xff0c;\u76f4\u63a5\u4f7f\u7528ThreadPoolExecutor&#xff0c;\u81ea\u5b9a\u4e49\u6709\u754c\u961f\u5217\u548c\u62d2\u7edd\u7b56\u7565\u3002<\/p>\n<h3>3.2 \u5751\u70b92&#xff1a;\u4efb\u52a1\u4e2d\u5b58\u5728\u672a\u6355\u83b7\u5f02\u5e38<\/h3>\n<p>\u95ee\u9898\u5206\u6790&#xff1a;\u7ebf\u7a0b\u6c60\u4e2d\u7684\u7ebf\u7a0b\u6267\u884c\u4efb\u52a1\u65f6&#xff0c;\u82e5\u4efb\u52a1\u629b\u51fa\u672a\u6355\u83b7\u5f02\u5e38&#xff08;\u5982RuntimeException&#xff09;&#xff0c;\u7ebf\u7a0b\u4f1a\u88ab\u9500\u6bc1&#xff0c;\u7ebf\u7a0b\u6c60\u4f1a\u521b\u5efa\u65b0\u7ebf\u7a0b\u66ff\u4ee3&#xff0c;\u5bfc\u81f4\u7ebf\u7a0b\u9891\u7e41\u521b\u5efa\u9500\u6bc1&#xff0c;\u6027\u80fd\u4e0b\u964d\u3002\u4e14\u5f02\u5e38\u4fe1\u606f\u53ef\u80fd\u88ab\u5ffd\u7565&#xff0c;\u96be\u4ee5\u6392\u67e5\u95ee\u9898\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u6848&#xff1a;<\/p>\n<li>\n<p>\u5728\u4efb\u52a1\u4e2d\u6dfb\u52a0try-catch\u5757&#xff0c;\u6355\u83b7\u6240\u6709\u5f02\u5e38\u5e76\u8bb0\u5f55\u65e5\u5fd7&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528ThreadFactory\u521b\u5efa\u7ebf\u7a0b\u65f6&#xff0c;\u8bbe\u7f6eUncaughtExceptionHandler\u6355\u83b7\u672a\u5904\u7406\u5f02\u5e38&#xff1a;<\/p>\n<\/li>\n<p>thread.setUncaughtExceptionHandler((t, e) -&gt; {<br \/>\n    log.error(&#034;\u7ebf\u7a0b{}\u6267\u884c\u4efb\u52a1\u65f6\u53d1\u751f\u5f02\u5e38&#034;, t.getName(), e);<br \/>\n});<\/p>\n<h3>3.3 \u5751\u70b93&#xff1a;\u7ebf\u7a0b\u6c60\u672a\u5173\u95ed\u5bfc\u81f4\u8d44\u6e90\u6cc4\u6f0f<\/h3>\n<p>\u95ee\u9898\u5206\u6790&#xff1a;\u7ebf\u7a0b\u6c60\u4e2d\u7684\u6838\u5fc3\u7ebf\u7a0b\u9ed8\u8ba4\u662f\u5e38\u9a7b\u7684&#xff0c;\u82e5\u7a0b\u5e8f\u9000\u51fa\u65f6\u672a\u5173\u95ed\u7ebf\u7a0b\u6c60&#xff0c;\u6838\u5fc3\u7ebf\u7a0b\u4f1a\u4e00\u76f4\u8fd0\u884c&#xff0c;\u5bfc\u81f4JVM\u65e0\u6cd5\u6b63\u5e38\u9000\u51fa&#xff0c;\u9020\u6210\u8d44\u6e90\u6cc4\u6f0f\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u6848&#xff1a;\u5728\u7a0b\u5e8f\u7ec8\u6b62\u65f6&#xff08;\u5982SpringBoot\u7684\u9500\u6bc1\u65b9\u6cd5&#xff09;&#xff0c;\u8c03\u7528\u7ebf\u7a0b\u6c60\u7684shutdown()\u6216shutdownNow()\u65b9\u6cd5\u5173\u95ed\u7ebf\u7a0b\u6c60&#xff1a;<\/p>\n<ul>\n<li>\n<p>shutdown()&#xff1a;\u5e73\u7f13\u5173\u95ed&#xff0c;\u4e0d\u518d\u63a5\u53d7\u65b0\u4efb\u52a1&#xff0c;\u7b49\u5f85\u5df2\u63d0\u4ea4\u7684\u4efb\u52a1\u6267\u884c\u5b8c\u6bd5&#xff1b;<\/p>\n<\/li>\n<li>\n<p>shutdownNow()&#xff1a;\u7acb\u5373\u5173\u95ed&#xff0c;\u5c1d\u8bd5\u4e2d\u65ad\u6b63\u5728\u6267\u884c\u7684\u4efb\u52a1&#xff0c;\u8fd4\u56de\u672a\u6267\u884c\u7684\u4efb\u52a1\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\/\/ SpringBoot\u4e2d\u5173\u95ed\u7ebf\u7a0b\u6c60\u793a\u4f8b<br \/>\n&#064;Component<br \/>\npublic class ThreadPoolShutdownHook implements DisposableBean {<\/p>\n<p>    &#064;Autowired<br \/>\n    private ExecutorService bizThreadPool;<\/p>\n<p>    &#064;Override<br \/>\n    public void destroy() throws Exception {<br \/>\n        if (bizThreadPool !&#061; null &amp;&amp; !bizThreadPool.isShutdown()) {<br \/>\n            bizThreadPool.shutdown();<br \/>\n            \/\/ \u7b49\u5f8510\u79d2&#xff0c;\u82e5\u4ecd\u672a\u5173\u95ed\u5219\u5f3a\u5236\u4e2d\u65ad<br \/>\n            if (!bizThreadPool.awaitTermination(10, TimeUnit.SECONDS)) {<br \/>\n                bizThreadPool.shutdownNow();<br \/>\n            }<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<h3>3.4 \u5751\u70b94&#xff1a;\u6ee5\u7528\u5355\u4f8b\u7ebf\u7a0b\u6c60<\/h3>\n<p>\u95ee\u9898\u5206\u6790&#xff1a;\u90e8\u5206\u5f00\u53d1\u8005\u4e3a\u4e86\u65b9\u4fbf&#xff0c;\u5168\u5c40\u4f7f\u7528\u4e00\u4e2a\u5355\u4f8b\u7ebf\u7a0b\u6c60\u5904\u7406\u6240\u6709\u4efb\u52a1\u3002\u82e5\u4e0d\u540c\u7c7b\u578b\u7684\u4efb\u52a1&#xff08;\u5982\u6838\u5fc3\u4efb\u52a1\u3001\u975e\u6838\u5fc3\u4efb\u52a1&#xff09;\u6df7\u5408\u6267\u884c&#xff0c;\u53ef\u80fd\u51fa\u73b0\u975e\u6838\u5fc3\u4efb\u52a1\u5360\u7528\u7ebf\u7a0b\u8d44\u6e90&#xff0c;\u5bfc\u81f4\u6838\u5fc3\u4efb\u52a1\u7b49\u5f85&#xff0c;\u5f71\u54cd\u7cfb\u7edf\u6838\u5fc3\u529f\u80fd\u54cd\u5e94\u901f\u5ea6\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u6848&#xff1a;\u6309\u4e1a\u52a1\u7c7b\u578b\u62c6\u5206\u7ebf\u7a0b\u6c60&#xff0c;\u5982&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u8ba2\u5355\u5904\u7406\u7ebf\u7a0b\u6c60&#xff1a;\u4e13\u95e8\u5904\u7406\u8ba2\u5355\u521b\u5efa\u3001\u652f\u4ed8\u7b49\u6838\u5fc3\u4efb\u52a1&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u65e5\u5fd7\u6536\u96c6\u7ebf\u7a0b\u6c60&#xff1a;\u4e13\u95e8\u5904\u7406\u65e5\u5fd7\u5199\u5165\u3001\u7edf\u8ba1\u7b49\u975e\u6838\u5fc3\u4efb\u52a1&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u5b9a\u65f6\u4efb\u52a1\u7ebf\u7a0b\u6c60&#xff1a;\u4e13\u95e8\u5904\u7406\u5b9a\u65f6\u8c03\u5ea6\u4efb\u52a1\u3002<\/p>\n<\/li>\n<\/ul>\n<h2>\u56db\u3001\u603b\u7ed3<\/h2>\n<p>\u7ebf\u7a0b\u6c60\u662fJava\u5e76\u53d1\u7f16\u7a0b\u7684\u6838\u5fc3\u5de5\u5177&#xff0c;\u5176\u6838\u5fc3\u4ef7\u503c\u5728\u4e8e\u201c\u8d44\u6e90\u590d\u7528\u201d\u4e0e\u201c\u5e76\u53d1\u63a7\u5236\u201d\u3002\u6b63\u786e\u4f7f\u7528\u7ebf\u7a0b\u6c60\u7684\u5173\u952e\u5728\u4e8e&#xff1a;<\/p>\n<li>\n<p>\u7406\u89e3\u6838\u5fc3\u53c2\u6570\u4e0e\u5de5\u4f5c\u6d41\u7a0b&#xff0c;\u7ed3\u5408\u4e1a\u52a1\u573a\u666f&#xff08;CPU\/IO\u5bc6\u96c6\u578b&#xff09;\u5408\u7406\u914d\u7f6e\u53c2\u6570&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u907f\u514d\u4f7f\u7528Executors&#xff0c;\u81ea\u5b9a\u4e49ThreadPoolExecutor&#xff0c;\u91c7\u7528\u6709\u754c\u961f\u5217\u548c\u5408\u9002\u7684\u62d2\u7edd\u7b56\u7565&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u91cd\u89c6\u5f02\u5e38\u5904\u7406\u4e0e\u7ebf\u7a0b\u6c60\u5173\u95ed&#xff0c;\u907f\u514d\u8d44\u6e90\u6cc4\u6f0f&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u6309\u4e1a\u52a1\u62c6\u5206\u7ebf\u7a0b\u6c60&#xff0c;\u4fdd\u969c\u6838\u5fc3\u4efb\u52a1\u7684\u4f18\u5148\u7ea7\u4e0e\u54cd\u5e94\u901f\u5ea6\u3002<\/p>\n<\/li>\n<p>\u5b9e\u8df5\u662f\u68c0\u9a8c\u771f\u7406\u7684\u552f\u4e00\u6807\u51c6&#xff0c;\u5efa\u8bae\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u7ed3\u5408\u7cfb\u7edf\u76d1\u63a7&#xff08;\u5982\u7ebf\u7a0b\u6570\u3001\u4efb\u52a1\u961f\u5217\u957f\u5ea6\u3001CPU\u5229\u7528\u7387&#xff09;\u6301\u7eed\u4f18\u5316\u7ebf\u7a0b\u6c60\u914d\u7f6e&#xff0c;\u8ba9\u5176\u771f\u6b63\u9002\u914d\u4e1a\u52a1\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728Java\u5e76\u53d1\u7f16\u7a0b\u4e2d&#xff0c;\u7ebf\u7a0b\u6c60\u662f\u63d0\u5347\u7a0b\u5e8f\u6027\u80fd\u3001\u4f18\u5316\u8d44\u6e90\u5229\u7528\u7387\u7684\u6838\u5fc3\u7ec4\u4ef6\u3002\u65e0\u8bba\u662f\u65e5\u5e38\u5f00\u53d1\u4e2d\u7684\u63a5\u53e3\u4f18\u5316\u3001\u6279\u91cf\u4efb\u52a1\u5904\u7406&#xff0c;\u8fd8\u662f\u9ad8\u5e76\u53d1\u573a\u666f\u4e0b\u7684\u6d41\u91cf\u627f\u8f7d&#xff0c;\u5408\u7406\u4f7f\u7528\u7ebf\u7a0b\u6c60\u90fd\u80fd\u8d77\u5230\u4e8b\u534a\u529f\u500d\u7684\u6548\u679c\u3002\u4f46\u5982\u679c\u5bf9\u7ebf\u7a0b\u6c60\u7684\u539f\u7406\u7406\u89e3\u4e0d\u900f\u5f7b&#xff0c;\u968f\u610f\u914d\u7f6e\u53c2\u6570&#xff0c;\u53cd\u800c\u53ef\u80fd\u5f15\u53d1\u7ebf\u7a0b\u6cc4\u6f0f\u3001\u8d44\u6e90\u8017\u5c3d\u7b49\u4e25\u91cd\u95ee\u9898\u3002\u672c\u6587\u5c06\u4ece\u7ebf\u7a0b\u6c60\u7684\u6838\u5fc3\u539f\u7406\u51fa\u53d1&#xff0c;\u7ed3\u5408\u5b9e\u9645\u5f00\u53d1\u573a\u666f&#xff0c;\u68b3\u7406\u7ebf\u7a0b\u6c60\u7684\u6b63\u786e\u4f7f\u7528\u65b9\u5f0f\u4e0e\u5e38\u89c1\u5751\u70b9&#xff0c;\u5e2e\u52a9\u5f00\u53d1\u8005\u5c11\u8d70\u5f2f\u8def<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,81,190],"topic":[],"class_list":["post-62914","post","type-post","status-publish","format-standard","hentry","category-server","tag-java","tag-python","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java\u7ebf\u7a0b\u6c60\u6838\u5fc3\u539f\u7406\u4e0e\u5b9e\u8df5\u907f\u5751\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/62914.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java\u7ebf\u7a0b\u6c60\u6838\u5fc3\u539f\u7406\u4e0e\u5b9e\u8df5\u907f\u5751\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u5728Java\u5e76\u53d1\u7f16\u7a0b\u4e2d&#xff0c;\u7ebf\u7a0b\u6c60\u662f\u63d0\u5347\u7a0b\u5e8f\u6027\u80fd\u3001\u4f18\u5316\u8d44\u6e90\u5229\u7528\u7387\u7684\u6838\u5fc3\u7ec4\u4ef6\u3002\u65e0\u8bba\u662f\u65e5\u5e38\u5f00\u53d1\u4e2d\u7684\u63a5\u53e3\u4f18\u5316\u3001\u6279\u91cf\u4efb\u52a1\u5904\u7406&#xff0c;\u8fd8\u662f\u9ad8\u5e76\u53d1\u573a\u666f\u4e0b\u7684\u6d41\u91cf\u627f\u8f7d&#xff0c;\u5408\u7406\u4f7f\u7528\u7ebf\u7a0b\u6c60\u90fd\u80fd\u8d77\u5230\u4e8b\u534a\u529f\u500d\u7684\u6548\u679c\u3002\u4f46\u5982\u679c\u5bf9\u7ebf\u7a0b\u6c60\u7684\u539f\u7406\u7406\u89e3\u4e0d\u900f\u5f7b&#xff0c;\u968f\u610f\u914d\u7f6e\u53c2\u6570&#xff0c;\u53cd\u800c\u53ef\u80fd\u5f15\u53d1\u7ebf\u7a0b\u6cc4\u6f0f\u3001\u8d44\u6e90\u8017\u5c3d\u7b49\u4e25\u91cd\u95ee\u9898\u3002\u672c\u6587\u5c06\u4ece\u7ebf\u7a0b\u6c60\u7684\u6838\u5fc3\u539f\u7406\u51fa\u53d1&#xff0c;\u7ed3\u5408\u5b9e\u9645\u5f00\u53d1\u573a\u666f&#xff0c;\u68b3\u7406\u7ebf\u7a0b\u6c60\u7684\u6b63\u786e\u4f7f\u7528\u65b9\u5f0f\u4e0e\u5e38\u89c1\u5751\u70b9&#xff0c;\u5e2e\u52a9\u5f00\u53d1\u8005\u5c11\u8d70\u5f2f\u8def\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/62914.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-20T14:57:55+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/62914.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/62914.html\",\"name\":\"Java\u7ebf\u7a0b\u6c60\u6838\u5fc3\u539f\u7406\u4e0e\u5b9e\u8df5\u907f\u5751\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-20T14:57:55+00:00\",\"dateModified\":\"2026-01-20T14:57:55+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/62914.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/62914.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/62914.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\u7ebf\u7a0b\u6c60\u6838\u5fc3\u539f\u7406\u4e0e\u5b9e\u8df5\u907f\u5751\u6307\u5357\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java\u7ebf\u7a0b\u6c60\u6838\u5fc3\u539f\u7406\u4e0e\u5b9e\u8df5\u907f\u5751\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/62914.html","og_locale":"zh_CN","og_type":"article","og_title":"Java\u7ebf\u7a0b\u6c60\u6838\u5fc3\u539f\u7406\u4e0e\u5b9e\u8df5\u907f\u5751\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u5728Java\u5e76\u53d1\u7f16\u7a0b\u4e2d&#xff0c;\u7ebf\u7a0b\u6c60\u662f\u63d0\u5347\u7a0b\u5e8f\u6027\u80fd\u3001\u4f18\u5316\u8d44\u6e90\u5229\u7528\u7387\u7684\u6838\u5fc3\u7ec4\u4ef6\u3002\u65e0\u8bba\u662f\u65e5\u5e38\u5f00\u53d1\u4e2d\u7684\u63a5\u53e3\u4f18\u5316\u3001\u6279\u91cf\u4efb\u52a1\u5904\u7406&#xff0c;\u8fd8\u662f\u9ad8\u5e76\u53d1\u573a\u666f\u4e0b\u7684\u6d41\u91cf\u627f\u8f7d&#xff0c;\u5408\u7406\u4f7f\u7528\u7ebf\u7a0b\u6c60\u90fd\u80fd\u8d77\u5230\u4e8b\u534a\u529f\u500d\u7684\u6548\u679c\u3002\u4f46\u5982\u679c\u5bf9\u7ebf\u7a0b\u6c60\u7684\u539f\u7406\u7406\u89e3\u4e0d\u900f\u5f7b&#xff0c;\u968f\u610f\u914d\u7f6e\u53c2\u6570&#xff0c;\u53cd\u800c\u53ef\u80fd\u5f15\u53d1\u7ebf\u7a0b\u6cc4\u6f0f\u3001\u8d44\u6e90\u8017\u5c3d\u7b49\u4e25\u91cd\u95ee\u9898\u3002\u672c\u6587\u5c06\u4ece\u7ebf\u7a0b\u6c60\u7684\u6838\u5fc3\u539f\u7406\u51fa\u53d1&#xff0c;\u7ed3\u5408\u5b9e\u9645\u5f00\u53d1\u573a\u666f&#xff0c;\u68b3\u7406\u7ebf\u7a0b\u6c60\u7684\u6b63\u786e\u4f7f\u7528\u65b9\u5f0f\u4e0e\u5e38\u89c1\u5751\u70b9&#xff0c;\u5e2e\u52a9\u5f00\u53d1\u8005\u5c11\u8d70\u5f2f\u8def","og_url":"https:\/\/www.wsisp.com\/helps\/62914.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-20T14:57:55+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/62914.html","url":"https:\/\/www.wsisp.com\/helps\/62914.html","name":"Java\u7ebf\u7a0b\u6c60\u6838\u5fc3\u539f\u7406\u4e0e\u5b9e\u8df5\u907f\u5751\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-20T14:57:55+00:00","dateModified":"2026-01-20T14:57:55+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/62914.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/62914.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/62914.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Java\u7ebf\u7a0b\u6c60\u6838\u5fc3\u539f\u7406\u4e0e\u5b9e\u8df5\u907f\u5751\u6307\u5357"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/62914","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=62914"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/62914\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=62914"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=62914"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=62914"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=62914"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}