{"id":52897,"date":"2025-08-11T21:14:22","date_gmt":"2025-08-11T13:14:22","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/52897.html"},"modified":"2025-08-11T21:14:22","modified_gmt":"2025-08-11T13:14:22","slug":"java%e8%bf%9b%e9%98%b6%e6%8a%80%e6%9c%af3-%e5%a4%9a%e7%ba%bf%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/52897.html","title":{"rendered":"Java\u8fdb\u9636\u6280\u672f3-\u591a\u7ebf\u7a0b"},"content":{"rendered":"<h2>\u7ebf\u7a0b<\/h2>\n<h3 style=\"background-color:transparent\">\u4e00. \u6982\u5ff5<\/h3>\n<p>\u7ebf\u7a0b&#xff08;Thread&#xff09;\u662f\u64cd\u4f5c\u7cfb\u7edf\u80fd\u591f\u8fdb\u884c\u8fd0\u7b97\u8c03\u5ea6\u7684\u6700\u5c0f\u5355\u4f4d&#xff0c;\u5b83\u88ab\u5305\u542b\u5728\u8fdb\u7a0b\u4e4b\u4e2d&#xff0c;\u662f\u8fdb\u7a0b\u4e2d\u7684\u5b9e\u9645\u8fd0\u4f5c\u5355\u4f4d\u3002\u4e00\u4e2a\u8fdb\u7a0b\u53ef\u4ee5\u5305\u542b\u591a\u4e2a\u7ebf\u7a0b&#xff0c;\u8fd9\u4e9b\u7ebf\u7a0b\u5171\u4eab\u8be5\u8fdb\u7a0b\u7684\u8d44\u6e90&#xff08;\u5982\u5185\u5b58\u7a7a\u95f4\u3001\u6587\u4ef6\u63cf\u8ff0\u7b26\u7b49&#xff09;&#xff0c;\u4f46\u540c\u65f6\u62e5\u6709\u5404\u81ea\u72ec\u7acb\u7684\u6267\u884c\u6808\u3001\u7a0b\u5e8f\u8ba1\u6570\u5668\u548c\u5bc4\u5b58\u5668\u96c6\u5408\u3002<\/p>\n<h5>\u7ebf\u7a0b\u7684\u6838\u5fc3\u7279\u5f81<\/h5>\n<li>\u8f7b\u91cf\u7ea7&#xff1a;\u76f8\u8f83\u4e8e\u8fdb\u7a0b&#xff0c;\u7ebf\u7a0b\u7684\u521b\u5efa\u3001\u9500\u6bc1\u548c\u5207\u6362\u6210\u672c\u66f4\u4f4e&#xff08;\u65e0\u9700\u91cd\u65b0\u5206\u914d\u72ec\u7acb\u5185\u5b58\u7a7a\u95f4&#xff09;\u3002<\/li>\n<li>\u8d44\u6e90\u5171\u4eab&#xff1a;\u540c\u4e00\u8fdb\u7a0b\u5185\u7684\u7ebf\u7a0b\u5171\u4eab\u8fdb\u7a0b\u7684\u5806\u5185\u5b58\u3001\u5168\u5c40\u53d8\u91cf\u3001\u6587\u4ef6\u53e5\u67c4\u7b49\u8d44\u6e90&#xff0c;\u4fbf\u4e8e\u7ebf\u7a0b\u95f4\u901a\u4fe1\u3002<\/li>\n<li>\u72ec\u7acb\u8c03\u5ea6&#xff1a;\u7ebf\u7a0b\u662f CPU \u8c03\u5ea6\u7684\u57fa\u672c\u5355\u4f4d&#xff0c;\u6bcf\u4e2a\u7ebf\u7a0b\u90fd\u6709\u81ea\u5df1\u7684\u6267\u884c\u8def\u5f84&#xff08;\u5373\u51fd\u6570\u8c03\u7528\u6808&#xff09;\u3002<\/li>\n<li>\u5e76\u53d1\u6267\u884c&#xff1a;\u591a\u4e2a\u7ebf\u7a0b\u53ef\u5728\u540c\u4e00\u8fdb\u7a0b\u5185\u5e76\u53d1\u8fd0\u884c&#xff0c;\u63d0\u9ad8\u7a0b\u5e8f\u6548\u7387&#xff08;\u5982\u591a\u4efb\u52a1\u5904\u7406\u65f6\u51cf\u5c11\u7b49\u5f85\u65f6\u95f4&#xff09;\u3002<\/li>\n<h5>\u4e0e\u8fdb\u7a0b\u7684\u5173\u7cfb<\/h5>\n<ul>\n<li>\u8fdb\u7a0b\u662f\u8d44\u6e90\u5206\u914d\u7684\u57fa\u672c\u5355\u4f4d&#xff0c;\u7ebf\u7a0b\u662f\u8c03\u5ea6\u6267\u884c\u7684\u57fa\u672c\u5355\u4f4d\u3002<\/li>\n<li>\u4e00\u4e2a\u8fdb\u7a0b\u81f3\u5c11\u5305\u542b\u4e00\u4e2a\u7ebf\u7a0b&#xff08;\u79f0\u4e3a\u4e3b\u7ebf\u7a0b&#xff09;&#xff0c;\u4e5f\u53ef\u521b\u5efa\u591a\u4e2a\u7ebf\u7a0b&#xff08;\u79f0\u4e3a\u5b50\u7ebf\u7a0b&#xff09;\u3002<\/li>\n<li>\u8fdb\u7a0b\u95f4\u8d44\u6e90\u76f8\u4e92\u72ec\u7acb&#xff0c;\u7ebf\u7a0b\u95f4\u8d44\u6e90\u5171\u4eab&#xff08;\u56e0\u6b64\u9700\u6ce8\u610f\u7ebf\u7a0b\u5b89\u5168\u95ee\u9898&#xff0c;\u5982\u7ade\u6001\u6761\u4ef6&#xff09;\u3002<\/li>\n<\/ul>\n<h5>\u4e3e\u4f8b\u8bf4\u660e<\/h5>\n<ul>\n<li>\u6253\u5f00\u4e00\u4e2a\u6d4f\u89c8\u5668&#xff08;\u8fdb\u7a0b&#xff09;&#xff0c;\u5176\u4e2d \u201c\u7f51\u9875\u6e32\u67d3\u201d\u201c\u4e0b\u8f7d\u6587\u4ef6\u201d\u201c\u64ad\u653e\u97f3\u9891\u201d \u7b49\u529f\u80fd\u53ef\u7531\u4e0d\u540c\u7ebf\u7a0b\u540c\u65f6\u6267\u884c&#xff0c;\u5b83\u4eec\u5171\u4eab\u6d4f\u89c8\u5668\u7684\u5185\u5b58\u548c\u7f51\u7edc\u8fde\u63a5\u3002<\/li>\n<\/ul>\n<h3 style=\"background-color:transparent\">\u4e8c. \u521b\u5efa\u7ebf\u7a0b\u7684\u56db\u79cd\u65b9\u5f0f<\/h3>\n<h4>1. \u7ee7\u627fThread\u7c7b\u5e76\u91cd\u5199run()\u65b9\u6cd5<\/h4>\n<p>\u6b65\u9aa4&#xff1a;<\/p>\n<\/p>\n<ul>\n<li>\u5b9a\u4e49\u7c7b\u7ee7\u627fjava.lang.Thread\u7c7b<\/li>\n<li>\u91cd\u5199run()\u65b9\u6cd5&#xff08;\u7ebf\u7a0b\u6267\u884c\u7684\u6838\u5fc3\u903b\u8f91&#xff09;<\/li>\n<li>\u521b\u5efa\u7ebf\u7a0b\u5bf9\u8c61\u5e76\u8c03\u7528start()\u65b9\u6cd5\u542f\u52a8\u7ebf\u7a0b&#xff08;\u800c\u975e\u76f4\u63a5\u8c03\u7528run()&#xff09;<\/li>\n<\/ul>\n<p>\u793a\u4f8b\u4ee3\u7801&#xff1a;<\/p>\n<p>package com.itheima.ReStudy2;<\/p>\n<p>public class Demo1 {<br \/>\n    public static void main(String[] args) {<br \/>\n        Thread t &#061; new MyThread();<br \/>\n        t.start();<br \/>\n    }<br \/>\n}<br \/>\nclass MyThread extends Thread{<br \/>\n    &#064;Override<br \/>\n    public void run() {<br \/>\n        System.out.println(&#034;\u606d\u559c\u4f60&#xff0c;\u521b\u5efa\u7ebf\u7a0b\u6210\u529f&#034;);<br \/>\n    }<br \/>\n}<\/p>\n<p>\u7279\u70b9&#xff1a;<\/p>\n<\/p>\n<ul>\n<li>\u5b9e\u73b0\u7b80\u5355&#xff0c;\u4f46\u53d7\u9650\u4e8e Java \u5355\u7ee7\u627f\u7279\u6027&#xff0c;\u7075\u6d3b\u6027\u8f83\u4f4e\u3002<\/li>\n<\/ul>\n<h4>2. \u5b9e\u73b0Runnable\u63a5\u53e3<\/h4>\n<p>\u6b65\u9aa4&#xff1a;<\/p>\n<\/p>\n<ul>\n<li>\u5b9a\u4e49\u7c7b\u5b9e\u73b0java.lang.Runnable\u63a5\u53e3<\/li>\n<li>\u5b9e\u73b0run()\u65b9\u6cd5&#xff08;\u7ebf\u7a0b\u6267\u884c\u903b\u8f91&#xff09;<\/li>\n<li>\u521b\u5efaThread\u5bf9\u8c61&#xff0c;\u5c06Runnable\u5b9e\u4f8b\u4f5c\u4e3a\u53c2\u6570\u4f20\u5165<\/li>\n<li>\u8c03\u7528Thread\u5bf9\u8c61\u7684start()\u65b9\u6cd5\u542f\u52a8\u7ebf\u7a0b<\/li>\n<\/ul>\n<p>\u793a\u4f8b\u4ee3\u7801&#xff1a;<\/p>\n<p>package com.itheima.ReStudy2;<\/p>\n<p>public class Demo2 {<br \/>\n    public static void main(String[] args) {<\/p>\n<p>        Thread t &#061;  new Thread(new MyThread2());<br \/>\n        t.start();<br \/>\n    }<br \/>\n}<br \/>\nclass MyThread2 implements Runnable{<br \/>\n    &#064;Override<br \/>\n    public void run() {<br \/>\n        System.out.println(&#034;\u606d\u559c\u4f60&#xff0c;\u901a\u8fc7Runnable\u63a5\u53e3\u6210\u529f\u5b9e\u73b0\u4e86\u4e00\u4e2a\u7ebf\u7a0b&#034;);<br \/>\n    }<br \/>\n}<\/p>\n<p>\u7279\u70b9&#xff1a;<\/p>\n<\/p>\n<ul>\n<li>\u907f\u514d\u5355\u7ee7\u627f\u9650\u5236&#xff0c;\u53ef\u540c\u65f6\u5b9e\u73b0\u5176\u4ed6\u63a5\u53e3&#xff0c;\u63a8\u8350\u4f18\u5148\u4f7f\u7528\u3002<\/li>\n<\/ul>\n<h4>3. \u5b9e\u73b0Callable\u63a5\u53e3&#xff08;\u5e26\u8fd4\u56de\u503c\u7684\u7ebf\u7a0b&#xff09;<\/h4>\n<p>\u6b65\u9aa4&#xff1a;<\/p>\n<\/p>\n<ul>\n<li>\u5b9a\u4e49\u7c7b\u5b9e\u73b0java.util.concurrent.Callable&lt;V&gt;\u63a5\u53e3&#xff08;V\u4e3a\u8fd4\u56de\u503c\u7c7b\u578b&#xff09;<\/li>\n<li>\u5b9e\u73b0call()\u65b9\u6cd5&#xff08;\u7ebf\u7a0b\u903b\u8f91&#xff0c;\u53ef\u8fd4\u56de\u7ed3\u679c\u5e76\u629b\u51fa\u5f02\u5e38&#xff09;<\/li>\n<li>\u521b\u5efaFutureTask&lt;V&gt;\u5bf9\u8c61\u5305\u88c5Callable\u5b9e\u4f8b&#xff08;\u7528\u4e8e\u83b7\u53d6\u8fd4\u56de\u503c&#xff09;<\/li>\n<li>\u521b\u5efaThread\u5bf9\u8c61\u4f20\u5165FutureTask&#xff0c;\u8c03\u7528start()\u542f\u52a8<\/li>\n<li>\u901a\u8fc7FutureTask\u7684get()\u65b9\u6cd5\u83b7\u53d6\u7ebf\u7a0b\u6267\u884c\u7ed3\u679c<\/li>\n<\/ul>\n<p>\u793a\u4f8b\u4ee3\u7801&#xff1a;<\/p>\n<p>package com.itheima.ReStudy2;<\/p>\n<p>import java.util.Objects;<br \/>\nimport java.util.concurrent.Callable;<br \/>\nimport java.util.concurrent.ExecutionException;<br \/>\nimport java.util.concurrent.FutureTask;<\/p>\n<p>public class DEmo3Callable {<br \/>\n    public static void main(String[] args) throws ExecutionException, InterruptedException {<br \/>\n        FutureTask f &#061; new FutureTask&lt;Object&gt;(new MyThread3());<br \/>\n        Thread t &#061; new Thread(f);<br \/>\n        t.start();<br \/>\n        String a &#061; (String) f.get();<br \/>\n\/\/        \u9700\u8981\u901a\u8fc7FutureTask\u83b7\u53d6Callable\u7684\u8fd4\u56de\u503c<br \/>\n        System.out.println(a);<br \/>\n    }<br \/>\n}<br \/>\nclass  MyThread3 implements Callable&lt;Object&gt;{<br \/>\n    &#064;Override<br \/>\n    public Object call() throws Exception {<br \/>\n        String a &#061; &#034;\u6267\u884cCallable\u6210\u529f \u8fd4\u56de\u4e86\u4e00\u4e2aString\u5b57\u7b26\u4e32&#xff01;&#034;;<br \/>\n        return a;<br \/>\n    }<br \/>\n}<\/p>\n<p>\u7279\u70b9&#xff1a;<\/p>\n<\/p>\n<ul>\n<li>\u652f\u6301\u8fd4\u56de\u6267\u884c\u7ed3\u679c&#xff0c;\u53ef\u629b\u51fa\u5f02\u5e38&#xff0c;\u9002\u7528\u4e8e\u9700\u8981\u7ebf\u7a0b\u6267\u884c\u7ed3\u679c\u7684\u573a\u666f&#xff08;\u5982\u5e76\u884c\u8ba1\u7b97&#xff09;\u3002<\/li>\n<\/ul>\n<p>\u6838\u5fc3\u533a\u522b\u603b\u7ed3<\/p>\n<table>\n<tr>\u65b9\u5f0f\u5b9e\u73b0\u590d\u6742\u5ea6\u662f\u5426\u6709\u8fd4\u56de\u503c\u7075\u6d3b\u6027\u9002\u7528\u573a\u666f<\/tr>\n<tbody>\n<tr>\n<td>\u7ee7\u627fThread<\/td>\n<td>\u7b80\u5355<\/td>\n<td>\u65e0<\/td>\n<td>\u4f4e&#xff08;\u5355\u7ee7\u627f&#xff09;<\/td>\n<td>\u7b80\u5355\u7ebf\u7a0b\u4efb\u52a1<\/td>\n<\/tr>\n<tr>\n<td>\u5b9e\u73b0Runnable<\/td>\n<td>\u4e2d\u7b49<\/td>\n<td>\u65e0<\/td>\n<td>\u9ad8<\/td>\n<td>\u591a\u7ebf\u7a0b\u5171\u4eab\u8d44\u6e90\u6216\u9700\u591a\u5b9e\u73b0<\/td>\n<\/tr>\n<tr>\n<td>\u5b9e\u73b0Callable<\/td>\n<td>\u8f83\u9ad8<\/td>\n<td>\u6709<\/td>\n<td>\u9ad8<\/td>\n<td>\u9700\u8981\u7ebf\u7a0b\u6267\u884c\u7ed3\u679c\u6216\u5f02\u5e38\u5904\u7406<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5b9e\u9645\u5f00\u53d1\u4e2d&#xff0c;Runnable\u548cCallable\u56e0\u7075\u6d3b\u6027\u66f4\u5e38\u7528&#xff0c;\u5c24\u5176\u662f\u914d\u5408\u7ebf\u7a0b\u6c60\u4f7f\u7528\u65f6\u3002<\/p>\n<h4 style=\"background-color:transparent\">4.\u7ebf\u7a0b\u6c60<\/h4>\n<p>\u5728 Java \u4e2d&#xff0c;\u7ebf\u7a0b\u6c60\u662f\u7ba1\u7406\u7ebf\u7a0b\u751f\u547d\u5468\u671f\u7684\u91cd\u8981\u673a\u5236&#xff0c;\u80fd\u591f\u6709\u6548\u907f\u514d\u9891\u7e41\u521b\u5efa \/ \u9500\u6bc1\u7ebf\u7a0b\u7684\u6027\u80fd\u5f00\u9500\u3002\u4f60\u63d0\u5230\u7684\u5e94\u8be5\u662fThreadPoolExecutor&#xff08;\u6838\u5fc3\u5b9e\u73b0\u7c7b&#xff09;\u548cExecutors&#xff08;\u5de5\u5177\u7c7b&#xff09;&#xff0c;\u4e0b\u9762\u8be6\u7ec6\u4ecb\u7ecd&#xff1a;<\/p>\n<h5>4.1 \u6838\u5fc3\u5b9e\u73b0\u7c7b&#xff1a;ThreadPoolExecutor<\/h5>\n<p>ThreadPoolExecutor\u662f\u7ebf\u7a0b\u6c60\u7684\u6838\u5fc3\u5b9e\u73b0\u7c7b&#xff0c;\u4f4d\u4e8ejava.util.concurrent\u5305\u4e0b&#xff0c;\u901a\u8fc7\u7075\u6d3b\u914d\u7f6e\u53c2\u6570\u53ef\u6ee1\u8db3\u4e0d\u540c\u573a\u666f\u9700\u6c42\u3002<\/p>\n<h5>\u6838\u5fc3\u6784\u9020\u53c2\u6570<\/h5>\n<p>public ThreadPoolExecutor(<br \/>\n    int corePoolSize,        \/\/ \u6838\u5fc3\u7ebf\u7a0b\u6570&#xff08;\u59cb\u7ec8\u5b58\u6d3b\u7684\u7ebf\u7a0b\u6570&#xff09;<br \/>\n    int maximumPoolSize,     \/\/ \u6700\u5927\u7ebf\u7a0b\u6570&#xff08;\u7ebf\u7a0b\u6c60\u5141\u8bb8\u7684\u6700\u5927\u7ebf\u7a0b\u6570&#xff09;<br \/>\n    long keepAliveTime,      \/\/ \u975e\u6838\u5fc3\u7ebf\u7a0b\u7a7a\u95f2\u8d85\u65f6\u65f6\u95f4<br \/>\n    TimeUnit unit,           \/\/ \u8d85\u65f6\u65f6\u95f4\u5355\u4f4d&#xff08;\u5982TimeUnit.SECONDS&#xff09;<br \/>\n    BlockingQueue&lt;Runnable&gt; workQueue,  \/\/ \u4efb\u52a1\u7b49\u5f85\u961f\u5217&#xff08;\u5b58\u653e\u672a\u6267\u884c\u7684\u4efb\u52a1&#xff09;<br \/>\n    ThreadFactory threadFactory,        \/\/ \u7ebf\u7a0b\u5de5\u5382&#xff08;\u7528\u4e8e\u521b\u5efa\u7ebf\u7a0b&#xff09;<br \/>\n    RejectedExecutionHandler handler    \/\/ \u62d2\u7edd\u7b56\u7565&#xff08;\u4efb\u52a1\u6ee1\u65f6\u7684\u5904\u7406\u65b9\u5f0f&#xff09;<br \/>\n)<\/p>\n<h5>\u5e38\u7528\u62d2\u7edd\u7b56\u7565<\/h5>\n<li>AbortPolicy&#xff08;\u9ed8\u8ba4&#xff09;&#xff1a;\u76f4\u63a5\u629b\u51faRejectedExecutionException\u5f02\u5e38<\/li>\n<li>CallerRunsPolicy&#xff1a;\u8ba9\u63d0\u4ea4\u4efb\u52a1\u7684\u7ebf\u7a0b\u81ea\u5df1\u6267\u884c\u4efb\u52a1<\/li>\n<li>DiscardPolicy&#xff1a;\u76f4\u63a5\u4e22\u5f03\u4efb\u52a1&#xff08;\u4e0d\u629b\u5f02\u5e38&#xff09;<\/li>\n<li>DiscardOldestPolicy&#xff1a;\u4e22\u5f03\u961f\u5217\u4e2d\u6700\u65e7\u7684\u4efb\u52a1&#xff0c;\u518d\u5c1d\u8bd5\u63d0\u4ea4\u65b0\u4efb\u52a1<\/li>\n<h5>\u793a\u4f8b\u4ee3\u7801&#xff1a;<\/h5>\n<p>package com.itheima.ReStudy2;<\/p>\n<p>import java.util.concurrent.ArrayBlockingQueue;<br \/>\nimport java.util.concurrent.Executors;<br \/>\nimport java.util.concurrent.ThreadPoolExecutor;<br \/>\nimport java.util.concurrent.TimeUnit;<\/p>\n<p>public class Demo4ThreadPoolExecutor {<br \/>\n    public static void main(String[] args) {<br \/>\n        ThreadPoolExecutor executor &#061; new ThreadPoolExecutor(<br \/>\n                3,\/\/\u6838\u5fc3\u7ebf\u7a0b\u6570<br \/>\n                5, \/\/\u6700\u5927\u7ebf\u7a0b\u6570<br \/>\n                10,\/\/\u7ebf\u7a0b\u7a7a\u95f2\u65f6\u95f4<br \/>\n                TimeUnit.SECONDS,\/\/\u9500\u6bc1\u65f6\u95f4\u5355\u4f4d<br \/>\n                new ArrayBlockingQueue&lt;&gt;(4),\/\/\u4efb\u52a1\u961f\u5217<br \/>\n                Executors.defaultThreadFactory(),\/\/\u7ebf\u7a0b\u5de5\u5382<br \/>\n                new ThreadPoolExecutor.AbortPolicy()\/\/\u62d2\u7edd\u7b56\u7565<br \/>\n        );<br \/>\n        for (int i &#061; 0; i &lt; 15; i&#043;&#043;) {<br \/>\n            executor.execute(new MyThread4());<br \/>\n            System.out.println(&#034;\u5f53\u524d\u7ebf\u7a0b\u6570&#xff1a;&#034;&#043;executor.getPoolSize());<br \/>\n            System.out.println(&#034;\u5f53\u524d\u6392\u961f\u7ebf\u7a0b\u6570&#xff1a;&#034;&#043;executor.getQueue().size());<br \/>\n            try {<br \/>\n                Thread.sleep(1000);<br \/>\n            } catch (InterruptedException e) {<br \/>\n                e.printStackTrace();<br \/>\n            }<br \/>\n        }<br \/>\n        executor.shutdown();<br \/>\n    }<br \/>\n}<br \/>\nclass MyThread4 implements Runnable{<br \/>\n    public void run()<br \/>\n    {<br \/>\n        System.out.println(Thread.currentThread().getName()&#043;&#034;\u6267\u884c\u4e86&#034;);<br \/>\n    }<br \/>\n}<\/p>\n<h5>4.2 \u5de5\u5177\u7c7b&#xff1a;Executors<\/h5>\n<p>Executors\u63d0\u4f9b\u4e86\u4fbf\u6377\u7684\u9759\u6001\u65b9\u6cd5&#xff0c;\u53ef\u5feb\u901f\u521b\u5efa\u9884\u914d\u7f6e\u7684\u7ebf\u7a0b\u6c60&#xff08;\u5e95\u5c42\u4ecd\u57fa\u4e8eThreadPoolExecutor&#xff09;&#xff0c;\u9002\u5408\u7b80\u5355\u573a\u666f\u3002\u4f46\u963f\u91cc\u5df4\u5df4\u5f00\u53d1\u624b\u518c\u4e0d\u63a8\u8350\u4f7f\u7528&#xff0c;\u56e0\u9ed8\u8ba4\u53c2\u6570\u53ef\u80fd\u5bfc\u81f4\u8d44\u6e90\u8017\u5c3d&#xff08;\u5982\u65e0\u754c\u961f\u5217&#xff09;\u3002<\/p>\n<h5>\u5e38\u7528\u65b9\u6cd5<\/h5>\n<li>\n<p>Executors.newFixedThreadPool(int nThreads)<\/p>\n<ul>\n<li>\u56fa\u5b9a\u5927\u5c0f\u7684\u7ebf\u7a0b\u6c60&#xff08;\u6838\u5fc3\u7ebf\u7a0b\u6570 &#061; \u6700\u5927\u7ebf\u7a0b\u6570&#xff09;<\/li>\n<li>\u961f\u5217\u4f7f\u7528LinkedBlockingQueue&#xff08;\u65e0\u754c&#xff0c;\u53ef\u80fd\u5806\u79ef\u5927\u91cf\u4efb\u52a1\u5bfc\u81f4 OOM<\/li>\n<\/ul>\n<\/li>\n<p>ExecutorService fixedPool &#061; Executors.newFixedThreadPool(5); \/\/ \u56fa\u5b9a5\u4e2a\u7ebf\u7a0b<\/p>\n<p>Executors.newCachedThreadPool()<\/p>\n<ul>\n<li>\u53ef\u7f13\u5b58\u7684\u7ebf\u7a0b\u6c60&#xff08;\u6838\u5fc3\u7ebf\u7a0b\u6570 &#061; 0&#xff0c;\u6700\u5927\u7ebf\u7a0b\u6570 &#061; Integer.MAX_VALUE&#xff09;<\/li>\n<li>\u7a7a\u95f2\u7ebf\u7a0b 60 \u79d2\u540e\u9500\u6bc1&#xff0c;\u9002\u5408\u77ed\u671f\u4efb\u52a1<\/li>\n<li>\u98ce\u9669&#xff1a;\u4efb\u52a1\u8fc7\u591a\u65f6\u53ef\u80fd\u521b\u5efa\u5927\u91cf\u7ebf\u7a0b\u5bfc\u81f4 OOM<\/li>\n<\/ul>\n<p>ExecutorService cachedPool &#061; Executors.newCachedThreadPool();<\/p>\n<p>Executors.newSingleThreadExecutor()<\/p>\n<ul>\n<li>\u5355\u7ebf\u7a0b\u6c60&#xff08;\u6838\u5fc3\u7ebf\u7a0b\u6570 &#061; \u6700\u5927\u7ebf\u7a0b\u6570 &#061; 1&#xff09;<\/li>\n<li>\u6240\u6709\u4efb\u52a1\u6309\u987a\u5e8f\u6267\u884c&#xff0c;\u9002\u5408\u9700\u8981\u4e32\u884c\u6267\u884c\u7684\u573a\u666f<\/li>\n<\/ul>\n<p>ExecutorService singlePool &#061; Executors.newSingleThreadExecutor();<\/p>\n<p>Executors.newScheduledThreadPool(int corePoolSize)<\/p>\n<ul>\n<li>\u5b9a\u65f6\u4efb\u52a1\u7ebf\u7a0b\u6c60&#xff0c;\u652f\u6301\u5ef6\u8fdf\u6267\u884c\u6216\u5468\u671f\u6027\u6267\u884c<\/li>\n<\/ul>\n<p>ScheduledExecutorService scheduledPool &#061; Executors.newScheduledThreadPool(3);<br \/>\n\/\/ \u5ef6\u8fdf1\u79d2\u540e\u6267\u884c<br \/>\nscheduledPool.schedule(() -&gt; System.out.println(&#034;\u5ef6\u8fdf\u6267\u884c&#034;), 1, TimeUnit.SECONDS);<br \/>\n\/\/ \u5ef6\u8fdf2\u79d2\u540e&#xff0c;\u6bcf3\u79d2\u6267\u884c\u4e00\u6b21<br \/>\nscheduledPool.scheduleAtFixedRate(() -&gt; System.out.println(&#034;\u5468\u671f\u6267\u884c&#034;), 2, 3, TimeUnit.SECONDS);<\/p>\n<h5>4.3 \u7ebf\u7a0b\u6c60\u4f7f\u7528\u6d41\u7a0b<\/h5>\n<li>\u521b\u5efa\u7ebf\u7a0b\u6c60&#xff08;\u63a8\u8350ThreadPoolExecutor\u624b\u52a8\u914d\u7f6e\u53c2\u6570&#xff09;<\/li>\n<li>\u901a\u8fc7submit()\u6216execute()\u63d0\u4ea4\u4efb\u52a1&#xff08;submit()\u53ef\u8fd4\u56deFuture\u83b7\u53d6\u7ed3\u679c&#xff09;<\/li>\n<li>\u4efb\u52a1\u6267\u884c\u5b8c\u6bd5\u540e&#xff0c;\u8c03\u7528shutdown()&#xff08;\u5e73\u7f13\u5173\u95ed&#xff09;\u6216shutdownNow()&#xff08;\u5f3a\u5236\u5173\u95ed&#xff09;<\/li>\n<h5>4.4 \u6838\u5fc3\u533a\u522b\u4e0e\u5efa\u8bae<\/h5>\n<table>\n<tr>\u7c7b\u578b\u4f18\u52bf\u52a3\u52bf\u5efa\u8bae\u573a\u666f<\/tr>\n<tbody>\n<tr>\n<td>ThreadPoolExecutor<\/td>\n<td>\u53c2\u6570\u53ef\u63a7&#xff0c;\u7075\u6d3b\u9002\u914d\u573a\u666f<\/td>\n<td>\u914d\u7f6e\u590d\u6742<\/td>\n<td>\u751f\u4ea7\u73af\u5883&#xff0c;\u9700\u7cbe\u7ec6\u63a7\u5236\u8d44\u6e90<\/td>\n<\/tr>\n<tr>\n<td>Executors\u5de5\u5177\u7c7b<\/td>\n<td>\u5feb\u901f\u521b\u5efa&#xff0c;\u4ee3\u7801\u7b80\u6d01<\/td>\n<td>\u9ed8\u8ba4\u53c2\u6570\u6709\u6f5c\u5728\u98ce\u9669&#xff08;\u5982 OOM&#xff09;<\/td>\n<td>\u7b80\u5355\u573a\u666f\u6216\u6d4b\u8bd5\u73af\u5883<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6700\u4f73\u5b9e\u8df5&#xff1a;\u751f\u4ea7\u73af\u5883\u4e2d\u63a8\u8350\u76f4\u63a5\u4f7f\u7528ThreadPoolExecutor&#xff0c;\u6839\u636e\u4e1a\u52a1\u9700\u6c42\u5408\u7406\u8bbe\u7f6e\u6838\u5fc3\u7ebf\u7a0b\u6570\u3001\u961f\u5217\u5927\u5c0f\u548c\u62d2\u7edd\u7b56\u7565&#xff0c;\u907f\u514d\u8d44\u6e90\u8017\u5c3d\u98ce\u9669\u3002<\/p>\n<h3>\u4e09. \u591a\u7ebf\u7a0b\u5e76\u53d1\u5b89\u5168\u89e3\u51b3<\/h3>\n<p>\u5728\u591a\u7ebf\u7a0b\u73af\u5883\u4e2d&#xff0c;\u5f53\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u64cd\u4f5c\u5171\u4eab\u8d44\u6e90\u65f6&#xff0c;\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6570\u636e\u4e0d\u4e00\u81f4\u3001\u903b\u8f91\u9519\u8bef\u7b49\u95ee\u9898&#xff0c;\u8fd9\u5c31\u662f\u5e76\u53d1\u5b89\u5168\u95ee\u9898\u3002<\/p>\n<h5>1. \u5e76\u53d1\u5b89\u5168\u95ee\u9898\u7684\u4ea7\u751f\u6761\u4ef6<\/h5>\n<li>\u591a\u7ebf\u7a0b\u73af\u5883&#xff1a;\u5b58\u5728\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u6267\u884c<\/li>\n<li>\u5171\u4eab\u8d44\u6e90&#xff1a;\u7ebf\u7a0b\u64cd\u4f5c\u540c\u4e00\u4efd\u53ef\u4fee\u6539\u7684\u8d44\u6e90&#xff08;\u5982\u5168\u5c40\u53d8\u91cf\u3001\u9759\u6001\u53d8\u91cf\u3001\u5bf9\u8c61\u5c5e\u6027\u7b49&#xff09;<\/li>\n<li>\u975e\u539f\u5b50\u64cd\u4f5c&#xff1a;\u5bf9\u5171\u4eab\u8d44\u6e90\u7684\u64cd\u4f5c\u4e0d\u662f\u4e00\u6b65\u5b8c\u6210\u7684&#xff08;\u5982i&#043;&#043;\u5b9e\u9645\u5305\u542b\u8bfb\u53d6\u3001\u4fee\u6539\u3001\u5199\u5165\u4e09\u6b65&#xff09;<\/li>\n<p>\u793a\u4f8b&#xff1a;\u4e0d\u5b89\u5168\u7684\u591a\u7ebf\u7a0b\u64cd\u4f5c<\/p>\n<p>public class UnsafeThreadDemo {<br \/>\n    private static int count &#061; 0; \/\/ \u5171\u4eab\u8d44\u6e90<\/p>\n<p>    public static void main(String[] args) throws InterruptedException {<br \/>\n        \/\/ \u521b\u5efa1000\u4e2a\u7ebf\u7a0b&#xff0c;\u6bcf\u4e2a\u7ebf\u7a0b\u5bf9count\u52a0100\u6b21<br \/>\n        Runnable task &#061; () -&gt; {<br \/>\n            for (int i &#061; 0; i &lt; 100; i&#043;&#043;) {<br \/>\n                count&#043;&#043;; \/\/ \u975e\u539f\u5b50\u64cd\u4f5c&#xff0c;\u5b58\u5728\u5b89\u5168\u95ee\u9898<br \/>\n            }<br \/>\n        };<\/p>\n<p>        Thread[] threads &#061; new Thread[1000];<br \/>\n        for (int i &#061; 0; i &lt; 1000; i&#043;&#043;) {<br \/>\n            threads[i] &#061; new Thread(task);<br \/>\n            threads[i].start();<br \/>\n        }<\/p>\n<p>        \/\/ \u7b49\u5f85\u6240\u6709\u7ebf\u7a0b\u6267\u884c\u5b8c\u6bd5<br \/>\n        for (int i &#061; 0; i &lt; 1000; i&#043;&#043;) {<br \/>\n            threads[i].join();<br \/>\n        }<\/p>\n<p>        System.out.println(&#034;\u6700\u7ec8\u7ed3\u679c&#xff1a;&#034; &#043; count); \/\/ \u9884\u671f100000&#xff0c;\u5b9e\u9645\u5f80\u5f80\u5c0f\u4e8e\u8be5\u503c<br \/>\n    }<br \/>\n}<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"51\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250811131421-6899ecadb2d4a.png\" width=\"193\" \/><\/p>\n<p>\u95ee\u9898\u539f\u56e0&#xff1a;\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u8bfb\u53d6count\u7684\u503c&#xff0c;\u4fee\u6539\u540e\u518d\u5199\u56de&#xff08;\u7531\u4e8e\u7ebf\u7a0b\u6267\u884c\u5e76\u53d1\u673a\u5236&#xff09;&#xff0c;\u5bfc\u81f4\u90e8\u5206\u589e\u91cf\u64cd\u4f5c\u88ab\u8986\u76d6\u3002<\/p>\n<h5>\u4e8c\u3001\u5e76\u53d1\u5b89\u5168\u95ee\u9898\u7684\u89e3\u51b3\u65b9\u6848<\/h5>\n<h6>1. \u540c\u6b65\u9501&#xff08;synchronized\u4ee3\u7801\u5757&#xff09;<\/h6>\n<p>\u901a\u8fc7\u00a0synchronized\u5173\u952e\u5b57\u9501\u5b9a\u5171\u4eab\u8d44\u6e90&#xff0c;\u786e\u4fdd\u540c\u4e00\u65f6\u95f4\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u6267\u884c\u4e34\u754c\u533a\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p>\u8bed\u6cd5&#xff1a;<\/p>\n<p>synchronized (\u9501\u5bf9\u8c61) { \/\/ \u64cd\u4f5c\u5171\u4eab\u8d44\u6e90\u7684\u4ee3\u7801&#xff08;\u4e34\u754c\u533a&#xff09; }<\/p>\n<p>\u793a\u4f8b&#xff1a;<\/p>\n<p>public class SynchronizedBlockDemo {<br \/>\n    private static int count &#061; 0;<br \/>\n    private static final Object lock &#061; new Object(); \/\/ \u9501\u5bf9\u8c61&#xff08;\u63a8\u8350\u4f7f\u7528\u4e13\u7528\u5bf9\u8c61&#xff09;<\/p>\n<p>    public static void main(String[] args) throws InterruptedException {<br \/>\n        Runnable task &#061; () -&gt; {<br \/>\n            for (int i &#061; 0; i &lt; 100; i&#043;&#043;) {<br \/>\n                synchronized (lock) { \/\/ \u9501\u5b9a\u4e34\u754c\u533a<br \/>\n                    count&#043;&#043;;<br \/>\n                }<br \/>\n            }<br \/>\n        };<\/p>\n<p>        \/\/ \u542f\u52a8\u7ebf\u7a0b\u903b\u8f91\u540c\u4e0a&#8230;<br \/>\n        Thread[] threads &#061; new Thread[1000];<br \/>\n        for (int i &#061; 0; i &lt; 1000; i&#043;&#043;) {<br \/>\n            threads[i] &#061; new Thread(task);<br \/>\n            threads[i].start();<br \/>\n        }<\/p>\n<p>        for (int i &#061; 0; i &lt; 1000; i&#043;&#043;) {<br \/>\n            threads[i].join();<br \/>\n        }<\/p>\n<p>        System.out.println(&#034;\u6700\u7ec8\u7ed3\u679c&#xff1a;&#034; &#043; count); \/\/ \u6b63\u786e\u8f93\u51fa100000<br \/>\n    }<br \/>\n}<\/p>\n<p>\u7279\u70b9&#xff1a;<\/p>\n<\/p>\n<ul>\n<li>\u9501\u5bf9\u8c61\u53ef\u4ee5\u662f\u4efb\u610f\u5bf9\u8c61&#xff0c;\u4f46\u591a\u4e2a\u7ebf\u7a0b\u5fc5\u987b\u4f7f\u7528\u540c\u4e00\u4e2a\u9501\u5bf9\u8c61\u624d\u80fd\u4fdd\u8bc1\u540c\u6b65<\/li>\n<li>\u63a8\u8350\u4f7f\u7528private static final Object\u4f5c\u4e3a\u9501\u5bf9\u8c61&#xff0c;\u907f\u514d\u9501\u5bf9\u8c61\u88ab\u4fee\u6539<\/li>\n<\/ul>\n<h6>2. \u540c\u6b65\u65b9\u6cd5&#xff08;synchronized\u65b9\u6cd5&#xff09;<\/h6>\n<p>\u5c06\u00a0synchronized\u5173\u952e\u5b57\u4fee\u9970\u5728\u65b9\u6cd5\u4e0a&#xff0c;\u6b64\u65f6\u9501\u5bf9\u8c61\u4e3a&#xff1a;<\/p>\n<\/p>\n<ul>\n<li>\u975e\u9759\u6001\u65b9\u6cd5&#xff1a;\u5f53\u524d\u5bf9\u8c61&#xff08;this&#xff09;<\/li>\n<li>\u9759\u6001\u65b9\u6cd5&#xff1a;\u5f53\u524d\u7c7b\u7684Class\u5bf9\u8c61<\/li>\n<\/ul>\n<p>\u793a\u4f8b&#xff1a;<\/p>\n<p>public class SynchronizedMethodDemo {<br \/>\n    private static int count &#061; 0;<\/p>\n<p>    \/\/ \u9759\u6001\u540c\u6b65\u65b9\u6cd5&#xff08;\u9501\u5bf9\u8c61\u4e3aSynchronizedMethodDemo.class&#xff09;<br \/>\n    private static synchronized void increment() {<br \/>\n        count&#043;&#043;;<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) throws InterruptedException {<br \/>\n        Runnable task &#061; () -&gt; {<br \/>\n            for (int i &#061; 0; i &lt; 100; i&#043;&#043;) {<br \/>\n                increment(); \/\/ \u8c03\u7528\u540c\u6b65\u65b9\u6cd5<br \/>\n            }<br \/>\n        };<\/p>\n<p>        \/\/ \u542f\u52a8\u7ebf\u7a0b\u903b\u8f91\u540c\u4e0a&#8230;<br \/>\n        Thread[] threads &#061; new Thread[1000];<br \/>\n        for (int i &#061; 0; i &lt; 1000; i&#043;&#043;) {<br \/>\n            threads[i] &#061; new Thread(task);<br \/>\n            threads[i].start();<br \/>\n        }<\/p>\n<p>        for (int i &#061; 0; i &lt; 1000; i&#043;&#043;) {<br \/>\n            threads[i].join();<br \/>\n        }<\/p>\n<p>        System.out.println(&#034;\u6700\u7ec8\u7ed3\u679c&#xff1a;&#034; &#043; count); \/\/ \u6b63\u786e\u8f93\u51fa100000<br \/>\n    }<br \/>\n}<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"57\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250811131421-6899ecadbf5d4.png\" width=\"206\" \/><\/p>\n<p>Lock\u76f8\u6bd4synchronized\u7684\u4f18\u52bf&#xff1a;<\/p>\n<\/p>\n<ul>\n<li>\u53ef\u4e2d\u65ad\u9501&#xff1a;\u652f\u6301tryLock(long time, TimeUnit unit)\u8d85\u65f6\u83b7\u53d6\u9501&#xff0c;\u907f\u514d\u6b7b\u9501<\/li>\n<li>\u53ef\u5c1d\u8bd5\u83b7\u53d6\u9501&#xff1a;tryLock()\u65b9\u6cd5\u5c1d\u8bd5\u83b7\u53d6\u9501&#xff0c;\u5931\u8d25\u5219\u7acb\u5373\u8fd4\u56de<\/li>\n<li>\u516c\u5e73\u9501&#xff1a;ReentrantLock\u53ef\u901a\u8fc7\u6784\u9020\u53c2\u6570new ReentrantLock(true)\u5b9e\u73b0\u516c\u5e73\u9501&#xff08;\u6309\u8bf7\u6c42\u987a\u5e8f\u83b7\u53d6\u9501&#xff09;<\/li>\n<li>\u53ef\u5206\u79bb\u9501&#xff1a;\u914d\u5408Condition\u5b9e\u73b0\u66f4\u7075\u6d3b\u7684\u7ebf\u7a0b\u901a\u4fe1<\/li>\n<\/ul>\n<h6 style=\"background-color:transparent\">3.\u4e09\u79cd\u65b9\u6848\u7684\u5bf9\u6bd4<\/h6>\n<table>\n<tr>\u65b9\u6848\u5b9e\u73b0\u65b9\u5f0f\u7075\u6d3b\u6027\u6027\u80fd&#xff08;\u4e00\u822c\u573a\u666f&#xff09;\u9002\u7528\u573a\u666f<\/tr>\n<tbody>\n<tr>\n<td>\u540c\u6b65\u4ee3\u7801\u5757<\/td>\n<td>synchronized(\u9501)<\/td>\n<td>\u4e2d\u7b49<\/td>\n<td>\u8f83\u597d<\/td>\n<td>\u9700\u9501\u5b9a\u4ee3\u7801\u7247\u6bb5\u65f6<\/td>\n<\/tr>\n<tr>\n<td>\u540c\u6b65\u65b9\u6cd5<\/td>\n<td>synchronized\u4fee\u9970\u65b9\u6cd5<\/td>\n<td>\u4f4e&#xff08;\u7c92\u5ea6\u7c97&#xff09;<\/td>\n<td>\u4e00\u822c<\/td>\n<td>\u7b80\u5355\u573a\u666f&#xff0c;\u6574\u4e2a\u65b9\u6cd5\u9700\u540c\u6b65\u65f6<\/td>\n<\/tr>\n<tr>\n<td>Lock\u9501<\/td>\n<td>\u663e\u5f0flock()\/unlock()<\/td>\n<td>\u9ad8<\/td>\n<td>\u8f83\u597d&#xff08;\u7ade\u4e89\u6fc0\u70c8\u65f6\u66f4\u4f18&#xff09;<\/td>\n<td>\u590d\u6742\u573a\u666f&#xff08;\u8d85\u65f6\u3001\u516c\u5e73\u9501\u7b49&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6700\u4f73\u5b9e\u8df5&#xff1a;<\/p>\n<\/p>\n<ul>\n<li>\u7b80\u5355\u573a\u666f\u4f18\u5148\u4f7f\u7528synchronized&#xff08;\u4ee3\u7801\u7b80\u6d01&#xff0c;JVM \u4f18\u5316\u66f4\u597d&#xff09;<\/li>\n<li>\u590d\u6742\u573a\u666f&#xff08;\u5982\u9700\u8981\u8d85\u65f6\u63a7\u5236\u3001\u516c\u5e73\u9501&#xff09;\u4f7f\u7528Lock<\/li>\n<li>\u5c3d\u91cf\u7f29\u5c0f\u540c\u6b65\u8303\u56f4&#xff08;\u53ea\u9501\u5fc5\u8981\u7684\u4ee3\u7801&#xff09;&#xff0c;\u51cf\u5c11\u7ebf\u7a0b\u963b\u585e\u65f6\u95f4<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb124\u6b21\uff0c\u70b9\u8d5e9\u6b21\uff0c\u6536\u85cf2\u6b21\u3002\u7ebf\u7a0b\uff08Thread\uff09\u662f\u64cd\u4f5c\u7cfb\u7edf\u80fd\u591f\u8fdb\u884c\uff0c\u5b83\u88ab\u5305\u542b\u5728\u8fdb\u7a0b\u4e4b\u4e2d\uff0c\u662f\u8fdb\u7a0b\u4e2d\u7684\u5b9e\u9645\u8fd0\u4f5c\u5355\u4f4d\u3002\u4e00\u4e2a\u8fdb\u7a0b\u53ef\u4ee5\u5305\u542b\u591a\u4e2a\u7ebf\u7a0b\uff0c\u8fd9\u4e9b\u7ebf\u7a0b\u5171\u4eab\u8be5\u8fdb\u7a0b\u7684\u8d44\u6e90\uff08\u5982\u5185\u5b58\u7a7a\u95f4\u3001\u6587\u4ef6\u63cf\u8ff0\u7b26\u7b49\uff09\uff0c\u4f46\u540c\u65f6\u62e5\u6709\u5404\u81ea\u72ec\u7acb\u7684\u6267\u884c\u6808\u3001\u7a0b\u5e8f\u8ba1\u6570\u5668\u548c\u5bc4\u5b58\u5668\u96c6\u5408\u3002<\/p>\n","protected":false},"author":2,"featured_media":52895,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,190],"topic":[],"class_list":["post-52897","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-java","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java\u8fdb\u9636\u6280\u672f3-\u591a\u7ebf\u7a0b - \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\/52897.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java\u8fdb\u9636\u6280\u672f3-\u591a\u7ebf\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb124\u6b21\uff0c\u70b9\u8d5e9\u6b21\uff0c\u6536\u85cf2\u6b21\u3002\u7ebf\u7a0b\uff08Thread\uff09\u662f\u64cd\u4f5c\u7cfb\u7edf\u80fd\u591f\u8fdb\u884c\uff0c\u5b83\u88ab\u5305\u542b\u5728\u8fdb\u7a0b\u4e4b\u4e2d\uff0c\u662f\u8fdb\u7a0b\u4e2d\u7684\u5b9e\u9645\u8fd0\u4f5c\u5355\u4f4d\u3002\u4e00\u4e2a\u8fdb\u7a0b\u53ef\u4ee5\u5305\u542b\u591a\u4e2a\u7ebf\u7a0b\uff0c\u8fd9\u4e9b\u7ebf\u7a0b\u5171\u4eab\u8be5\u8fdb\u7a0b\u7684\u8d44\u6e90\uff08\u5982\u5185\u5b58\u7a7a\u95f4\u3001\u6587\u4ef6\u63cf\u8ff0\u7b26\u7b49\uff09\uff0c\u4f46\u540c\u65f6\u62e5\u6709\u5404\u81ea\u72ec\u7acb\u7684\u6267\u884c\u6808\u3001\u7a0b\u5e8f\u8ba1\u6570\u5668\u548c\u5bc4\u5b58\u5668\u96c6\u5408\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/52897.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-11T13:14:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250811131421-6899ecadb2d4a.png\" \/>\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=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/52897.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/52897.html\",\"name\":\"Java\u8fdb\u9636\u6280\u672f3-\u591a\u7ebf\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-08-11T13:14:22+00:00\",\"dateModified\":\"2025-08-11T13:14:22+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/52897.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/52897.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/52897.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\u8fdb\u9636\u6280\u672f3-\u591a\u7ebf\u7a0b\"}]},{\"@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\u8fdb\u9636\u6280\u672f3-\u591a\u7ebf\u7a0b - \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\/52897.html","og_locale":"zh_CN","og_type":"article","og_title":"Java\u8fdb\u9636\u6280\u672f3-\u591a\u7ebf\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb124\u6b21\uff0c\u70b9\u8d5e9\u6b21\uff0c\u6536\u85cf2\u6b21\u3002\u7ebf\u7a0b\uff08Thread\uff09\u662f\u64cd\u4f5c\u7cfb\u7edf\u80fd\u591f\u8fdb\u884c\uff0c\u5b83\u88ab\u5305\u542b\u5728\u8fdb\u7a0b\u4e4b\u4e2d\uff0c\u662f\u8fdb\u7a0b\u4e2d\u7684\u5b9e\u9645\u8fd0\u4f5c\u5355\u4f4d\u3002\u4e00\u4e2a\u8fdb\u7a0b\u53ef\u4ee5\u5305\u542b\u591a\u4e2a\u7ebf\u7a0b\uff0c\u8fd9\u4e9b\u7ebf\u7a0b\u5171\u4eab\u8be5\u8fdb\u7a0b\u7684\u8d44\u6e90\uff08\u5982\u5185\u5b58\u7a7a\u95f4\u3001\u6587\u4ef6\u63cf\u8ff0\u7b26\u7b49\uff09\uff0c\u4f46\u540c\u65f6\u62e5\u6709\u5404\u81ea\u72ec\u7acb\u7684\u6267\u884c\u6808\u3001\u7a0b\u5e8f\u8ba1\u6570\u5668\u548c\u5bc4\u5b58\u5668\u96c6\u5408\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/52897.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-08-11T13:14:22+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250811131421-6899ecadb2d4a.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/52897.html","url":"https:\/\/www.wsisp.com\/helps\/52897.html","name":"Java\u8fdb\u9636\u6280\u672f3-\u591a\u7ebf\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-08-11T13:14:22+00:00","dateModified":"2025-08-11T13:14:22+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/52897.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/52897.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/52897.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Java\u8fdb\u9636\u6280\u672f3-\u591a\u7ebf\u7a0b"}]},{"@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\/52897","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=52897"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/52897\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/52895"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=52897"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=52897"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=52897"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=52897"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}