{"id":10008315,"date":"2023-09-22T16:29:53","date_gmt":"2023-09-22T08:29:53","guid":{"rendered":"https:\/\/blog.itmax.cn\/?p=10008315"},"modified":"2023-09-22T16:29:53","modified_gmt":"2023-09-22T08:29:53","slug":"%e6%b7%b1%e5%85%a5%e6%b5%85%e5%87%ba%e7%ba%bf%e7%a8%8b%e6%b1%a0-%e4%ba%ac%e4%b8%9c%e4%ba%91%e6%8a%80%e6%9c%af%e5%9b%a2%e9%98%9f","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10008315","title":{"rendered":"\u6df1\u5165\u6d45\u51fa\u7ebf\u7a0b\u6c60 | \u4eac\u4e1c\u4e91\u6280\u672f\u56e2\u961f"},"content":{"rendered":"<h2>\u4e00\u3001\u7ebf\u7a0b<\/h2>\n<h3>1\u3001\u4ec0\u4e48\u662f\u7ebf\u7a0b<\/h3>\n<p><strong>\u7ebf\u7a0b<\/strong>(thread)\u662f\u64cd\u4f5c\u7cfb\u7edf\u80fd\u591f\u8fdb\u884c\u8fd0\u7b97\u8c03\u5ea6\u7684\u6700\u5c0f\u5355\u4f4d\u3002\u5b83\u88ab\u5305\u542b\u5728\u8fdb\u7a0b\u4e4b\u4e2d\uff0c\u662f\u8fdb\u7a0b\u4e2d\u7684\u5b9e\u9645 \u8fd0\u4f5c\u5355\u4f4d\u3002\u4e00\u6761\u7ebf\u7a0b\u6307\u7684\u662f\u8fdb\u7a0b\u4e2d\u4e00\u4e2a\u5355\u4e00\u987a\u5e8f\u7684\u63a7\u5236\u6d41\uff0c\u4e00\u4e2a\u8fdb\u7a0b\u4e2d\u53ef\u4ee5\u5e76\u53d1\u591a\u4e2a\u7ebf\u7a0b\uff0c\u6bcf\u6761\u7ebf \u7a0b\u5e76\u884c\u6267\u884c\u4e0d\u540c\u7684\u4efb\u52a1\u3002<\/p>\n<h3>2\u3001\u5982\u4f55\u521b\u5efa\u7ebf\u7a0b<\/h3>\n<h4>2.1\u3001JAVA\u4e2d\u521b\u5efa\u7ebf\u7a0b<\/h4>\n<pre><code>\/**\n * \u7ee7\u627fThread\u7c7b\uff0c\u91cd\u5199run\u65b9\u6cd5\n *\/\nclass MyThread extends Thread {\n    @Override\n    public void run() {\n        System.out.println(&quot;myThread...&quot; + Thread.currentThread().getName());\n} }\n\n\/**\n * \u5b9e\u73b0Runnable\u63a5\u53e3\uff0c\u5b9e\u73b0run\u65b9\u6cd5 \n *\/\nclass MyRunnable implements Runnable {\n    @Override\n    public void run() {\n        System.out.println(&quot;MyRunnable...&quot; + Thread.currentThread().getName());\n} }\n\n\/**\n * \u5b9e\u73b0Callable\u63a5\u53e3\uff0c\u6307\u5b9a\u8fd4\u56de\u7c7b\u578b\uff0c\u5b9e\u73b0call\u65b9\u6cd5\n *\/\nclass MyCallable implements Callable&lt;String&gt; {\n    @Override\n    public String call() throws Exception {\n        return &quot;MyCallable...&quot; + Thread.currentThread().getName();\n} }\n<\/code><\/pre>\n<h4>2.2\u3001\u6d4b\u8bd5\u4e00\u4e0b<\/h4>\n<pre><code>public static void main(String[] args) throws Exception {\n    MyThread thread = new MyThread();\n    thread.run();   \/\/myThread...main\n    thread.start(); \/\/myThread...Thread-0\n    \n    MyRunnable myRunnable = new MyRunnable();\n    Thread thread1 = new Thread(myRunnable);\n    myRunnable.run();   \/\/MyRunnable...main\n    thread1.start();    \/\/MyRunnable...Thread-1\n    \n    MyCallable myCallable = new MyCallable();\n    FutureTask&lt;String&gt; futureTask = new FutureTask&lt;&gt;(myCallable);\n    Thread thread2 = new Thread(futureTask);\n    thread2.start();\n    System.out.println(myCallable.call());  \/\/MyCallable...main\n    System.out.println(futureTask.get());   \/\/MyCallable...Thread-2\n\n} \n<\/code><\/pre>\n<h4>2.3\u3001\u95ee\u9898<\/h4>\n<p>\u65e2\u7136\u6211\u4eec\u521b\u5efa\u4e86\u7ebf\u7a0b\uff0c\u90a3\u4e3a\u4f55\u6211\u4eec\u76f4\u63a5\u8c03\u7528\u65b9\u6cd5\u548c\u6211\u4eec\u8c03\u7528start()\u65b9\u6cd5\u7684\u7ed3\u679c\u4e0d\u540c?new Thread() \u662f\u5426\u771f\u5b9e\u521b\u5efa\u4e86\u7ebf\u7a0b?<\/p>\n<h4>2.4\u3001\u95ee\u9898\u5206\u6790<\/h4>\n<p>\u6211\u4eec\u76f4\u63a5\u8c03\u7528\u65b9\u6cd5\uff0c\u53ef\u4ee5\u770b\u5230\u662f\u6267\u884c\u7684\u4e3b\u7ebf\u7a0b\uff0c\u800c\u8c03\u7528start()\u65b9\u6cd5\u5c31\u662f\u5f00\u542f\u4e86\u65b0\u7ebf\u7a0b\uff0c\u90a3\u8bf4\u660enew Thread()\u5e76\u6ca1\u6709\u521b\u5efa\u7ebf\u7a0b\uff0c\u800c\u662f\u5728start()\u4e2d\u521b\u5efa\u4e86\u7ebf\u7a0b\u3002<\/p>\n<p>\u90a3\u6211\u4eec\u770b\u4e0bThread\u7c7bstart()\u65b9\u6cd5:<\/p>\n<pre><code>class Thread implements Runnable { \/\/Thread\u7c7b\u5b9e\u73b0\u4e86Runnalbe\u63a5\u53e3\uff0c\u5b9e\u73b0\u4e86run()\u65b9\u6cd5 \n    \n    private Runnable target;\n\n    public synchronized void start() {\n        ...\n\n        boolean started = false;\n        try {\n            start0(); \/\/\u53ef\u4ee5\u770b\u5230\uff0cstart()\u65b9\u6cd5\u771f\u5b9e\u7684\u8c03\u7528\u65f6start0()\u65b9\u6cd5 \n            started = true;\n        } finally {\n            ...     \n        } \n    }\n    \n    private native void start0();  \/\/start0()\u662f\u4e00\u4e2anative\u65b9\u6cd5\uff0c\u7531JVM\u8c03\u7528\u5e95\u5c42\u64cd\u4f5c\u7cfb\u7edf\uff0c\u5f00\u542f\u4e00\u4e2a\u7ebf\u7a0b\uff0c\u7531\u64cd\u4f5c\u7cfb\u7edf\u8fc7\u7edf\u4e00\u8c03\u5ea6 \n\n    @Override\n    public void run() {\n        if (target != null) {\n             target.run(); \/\/\u64cd\u4f5c\u7cfb\u7edf\u5728\u6267\u884c\u65b0\u5f00\u542f\u7684\u7ebf\u7a0b\u65f6\uff0c\u56de\u8c03Runnable\u63a5\u53e3\u7684run()\u65b9\u6cd5\uff0c\u6267\u884c\u6211\u4eec\u9884\u8bbe\u7684\u7ebf\u7a0b\u4efb\u52a1\n\n        } \n     } \n} \n<\/code><\/pre>\n<h4>2.5\u3001\u603b\u7ed3<\/h4>\n<ol>\n<li>JAVA\u4e0d\u80fd\u76f4\u63a5\u521b\u5efa\u7ebf\u7a0b\u6267\u884c\u4efb\u52a1\uff0c\u800c\u662f\u901a\u8fc7\u521b\u5efaThread\u5bf9\u8c61\u8c03\u7528\u64cd\u4f5c\u7cfb\u7edf\u5f00\u542f\u7ebf\u7a0b\uff0c\u5728\u7531\u64cd\u4f5c\u7cfb \u7edf\u56de\u8c03Runnable\u63a5\u53e3\u7684run()\u65b9\u6cd5\u6267\u884c\u4efb\u52a1;<\/li>\n<li>\u5b9e\u73b0Runnable\u7684\u65b9\u5f0f\uff0c\u5c06\u7ebf\u7a0b\u5b9e\u9645\u8981\u6267\u884c\u7684\u56de\u8c03\u4efb\u52a1\u5355\u72ec\u63d0\u51fa\u6765\u4e86\uff0c\u5b9e\u73b0\u7ebf\u7a0b\u7684\u542f\u52a8\u4e0e\u56de\u8c03\u4efb\u52a1 \u89e3\u8026;<\/li>\n<li>\u5b9e\u73b0Callable\u7684\u65b9\u5f0f\uff0c\u901a\u8fc7Future\u6a21\u5f0f\u4e0d\u4f46\u5c06\u7ebf\u7a0b\u7684\u542f\u52a8\u4e0e\u56de\u8c03\u4efb\u52a1\u89e3\u8026\uff0c\u800c\u4e14\u53ef\u4ee5\u5728\u6267\u884c\u5b8c\u6210\u540e \u83b7\u53d6\u5230\u6267\u884c\u7684\u7ed3\u679c;<\/li>\n<\/ol>\n<h2>\u4e8c\u3001\u591a\u7ebf\u7a0b<\/h2>\n<h3>1\u3001\u4ec0\u4e48\u662f\u591a\u7ebf\u7a0b<\/h3>\n<p><strong>\u591a\u7ebf\u7a0b<\/strong>(multithreading)\uff0c\u662f\u6307\u4ece\u8f6f\u4ef6\u6216\u8005\u786c\u4ef6\u4e0a\u5b9e\u73b0\u591a\u4e2a\u7ebf\u7a0b\u5e76\u53d1\u6267\u884c\u7684\u6280\u672f\u3002\u540c\u4e00\u4e2a\u7ebf\u7a0b\u53ea \u80fd\u5904\u7406\u5b8c\u4e00\u4e2a\u4efb\u52a1\u5728\u5904\u7406\u4e0b\u4e00\u4e2a\u4efb\u52a1\uff0c\u6709\u65f6\u6211\u4eec\u9700\u8981\u591a\u4e2a\u4efb\u52a1\u540c\u65f6\u5904\u7406\uff0c\u8fd9\u65f6\uff0c\u6211\u4eec\u5c31\u9700\u8981\u521b\u5efa\u591a \u4e2a\u7ebf\u7a0b\u6765\u540c\u65f6\u5904\u7406\u4efb\u52a1\u3002<\/p>\n<h3>2\u3001\u591a\u7ebf\u7a0b\u6709\u4ec0\u4e48\u597d\u5904<\/h3>\n<h4>2.1\u3001\u4e32\u884c\u5904\u7406<\/h4>\n<pre><code>public static void main(String[] args) throws Exception {\n    System.out.println(&quot;start...&quot;);\n    long start = System.currentTimeMillis();\n    for (int i = 0; i &lt; 5; i++) {\n        Thread.sleep(2000);  \/\/\u6bcf\u4e2a\u4efb\u52a1\u6267\u884c2\u79d2 \n        System.out.println(&quot;task done...&quot;); \/\/\u5904\u7406\u6267\u884c\u7ed3\u679c\n    }\n    long end = System.currentTimeMillis();\n    System.out.println(&quot;end...,time = &quot;  + (end - start));\n}\n\/\/\u6267\u884c\u7ed3\u679c\nstart...\ntask done...\ntask done...\ntask done...\ntask done...\ntask done... end...,time = 10043\n<\/code><\/pre>\n<h4>2.2\u3001\u5e76\u884c\u5904\u7406<\/h4>\n<pre><code>public static void main(String[] args) throws Exception {\n    System.out.println(&quot;start...&quot;);\n    long start = System.currentTimeMillis();\n    List&lt;Future&gt; list = new ArrayList&lt;&gt;();\n\n    for (int i = 0; i &lt; 5; i++) {\n        Callable&lt;String&gt; callable = new Callable&lt;String&gt;() {\n            @Override\n            public String call() throws Exception {\n                Thread.sleep(2000); \/\/\u6bcf\u4e2a\u4efb\u52a1\u6267\u884c2\u79d2 \n                return &quot;task done...&quot;;\n            }\n\n        };\n        FutureTask task = new FutureTask(callable);\n        list.add(task);\n        new Thread(task).start();\n\n    }\n    \n    list.forEach(future -&gt; {\n        try { \n            System.out.println(future.get()); \/\/\u5904\u7406\u6267\u884c\u7ed3\u679c } catch (Exception e) {\n         } \n    });\n    \n    long end = System.currentTimeMillis();\n    System.out.println(&quot;end...,time = &quot; + (end - start));\n\n} \n\/\/\u6267\u884c\u7ed3\u679c\n start...\n task done...\n task done...\n task done...\n task done...\n task done... end...,time = 2005 \n<\/code><\/pre>\n<h4>2.3\u3001\u603b\u7ed3<\/h4>\n<ol>\n<li>\u591a\u7ebf\u7a0b\u53ef\u4ee5\u628a\u4e00\u4e2a\u4efb\u52a1\u62c6\u5206\u4e3a\u51e0\u4e2a\u5b50\u4efb\u52a1\uff0c\u591a\u4e2a\u5b50\u4efb\u52a1\u53ef\u4ee5\u5e76\u53d1\u6267\u884c\uff0c\u6bcf\u4e00\u4e2a\u5b50\u4efb\u52a1\u5c31\u662f\u4e00\u4e2a\u7ebf\u7a0b\u3002<\/li>\n<li>\u591a\u7ebf\u7a0b\u662f\u4e3a\u4e86\u540c\u6b65\u5b8c\u6210\u591a\u9879\u4efb\u52a1\uff0c\u4e0d\u662f\u4e3a\u4e86\u63d0\u9ad8\u8fd0\u884c\u6548\u7387\uff0c\u800c\u662f\u4e3a\u4e86\u63d0\u9ad8\u8d44\u6e90\u4f7f\u7528\u6548\u7387\u6765\u63d0\u9ad8\u7cfb\u7edf \u7684\u6548\u7387\u3002<\/li>\n<\/ol>\n<h4>2.4\u3001\u591a\u7ebf\u7a0b\u7684\u95ee\u9898<\/h4>\n<p>\u4e0a\u9762\u793a\u4f8b\u4e2d\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0c\u5982\u679c\u6bcf\u6765\u4e00\u4e2a\u4efb\u52a1\uff0c\u6211\u4eec\u5c31\u521b\u5efa\u4e00\u4e2a\u7ebf\u7a0b\uff0c\u6709\u5f88\u591a\u4efb\u52a1\u7684\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec \u4f1a\u521b\u5efa\u5927\u91cf\u7684\u7ebf\u7a0b\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u7cfb\u7edf\u8d44\u6e90\u7684\u8017\u5c3d\u3002\u540c\u65f6\uff0c\u6211\u4eec\u77e5\u9053\u7ebf\u7a0b\u7684\u6267\u884c\u662f\u9700\u8981\u62a2\u5360CPU\u8d44\u6e90 \u7684\uff0c\u90a3\u5982\u679c\u6709\u592a\u591a\u7684\u7ebf\u7a0b\uff0c\u5c31\u4f1a\u5bfc\u81f4\u5927\u91cf\u65f6\u95f4\u7528\u5728\u7ebf\u7a0b\u5207\u6362\u7684\u5f00\u9500\u4e0a\u3002<\/p>\n<p>\u518d\u6709\uff0c\u6bcf\u6765\u4e00\u4e2a\u4efb\u52a1\u90fd\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u7ebf\u7a0b\uff0c\u800c\u521b\u5efa\u4e00\u4e2a\u7ebf\u7a0b\u9700\u8981\u8c03\u7528\u64cd\u4f5c\u7cfb\u7edf\u5e95\u5c42\u65b9\u6cd5\uff0c\u5f00\u9500\u8f83 \u5927\uff0c\u800c\u7ebf\u7a0b\u6267\u884c\u5b8c\u6210\u540e\u5c31\u88ab\u56de\u6536\u4e86\u3002\u5728\u9700\u8981\u5927\u91cf\u7ebf\u7a0b\u7684\u65f6\u5019\uff0c\u521b\u5efa\u7ebf\u7a0b\u7684\u65f6\u95f4\u5c31\u82b1\u8d39\u4e0d\u5c11\u4e86\u3002<\/p>\n<h2>\u4e09\u3001\u7ebf\u7a0b\u6c60<\/h2>\n<h3>1\u3001\u5982\u4f55\u8bbe\u8ba1\u4e00\u4e2a\u7ebf\u7a0b\u6c60<\/h3>\n<p>\u7531\u4e8e\u591a\u7ebf\u7a0b\u7684\u5f00\u53d1\u5b58\u5728\u4e0a\u8ff0\u7684\u4e00\u4e9b\u95ee\u9898\uff0c\u90a3\u6211\u4eec\u662f\u5426\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a\u4e1c\u897f\u6765\u907f\u514d\u8fd9\u4e9b\u95ee\u9898\u5462?\u5f53\u7136\u53ef\u4ee5! \u7ebf\u7a0b\u6c60\u5c31\u662f\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\u800c\u751f\u7684\u3002\u90a3\u6211\u4eec\u8be5\u5982\u4f55\u8bbe\u8ba1\u4e00\u4e2a\u7ebf\u7a0b\u6c60\u6765\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\u5462?\u6216\u8005\u8bf4\uff0c\u4e00\u4e2a\u7ebf\u7a0b\u6c60\u8be5\u5177\u5907\u4ec0\u4e48\u6837\u7684\u529f\u80fd?<\/p>\n<h4>1.1\u3001\u7ebf\u7a0b\u6c60\u57fa\u672c\u529f\u80fd<\/h4>\n<ol>\n<li>\u591a\u7ebf\u7a0b\u4f1a\u521b\u5efa\u5927\u91cf\u7684\u7ebf\u7a0b\u8017\u5c3d\u8d44\u6e90\uff0c\u90a3\u7ebf\u7a0b\u6c60\u5e94\u8be5\u5bf9\u7ebf\u7a0b\u6570\u91cf\u6709\u6240\u9650\u5236\uff0c\u53ef\u4ee5\u4fdd\u8bc1\u4e0d\u4f1a\u8017\u5c3d\u7cfb\u7edf\u8d44 \u6e90;<\/li>\n<li>\u6bcf\u6b21\u521b\u5efa\u65b0\u7684\u7ebf\u7a0b\u4f1a\u589e\u52a0\u521b\u5efa\u65f6\u7684\u5f00\u9500\uff0c\u90a3\u7ebf\u7a0b\u6c60\u5e94\u8be5\u51cf\u5c11\u7ebf\u7a0b\u7684\u521b\u5efa\uff0c\u5c3d\u91cf\u590d\u7528\u5df2\u521b\u5efa\u597d\u7684\u7ebf \u7a0b;<\/li>\n<\/ol>\n<h4>1.2\u3001\u7ebf\u7a0b\u6c60\u9762\u4e34\u95ee\u9898<\/h4>\n<ol>\n<li>\u6211\u4eec\u77e5\u9053\u7ebf\u7a0b\u5728\u6267\u884c\u5b8c\u81ea\u5df1\u7684\u4efb\u52a1\u540e\u5c31\u4f1a\u88ab\u56de\u6536\uff0c\u90a3\u6211\u4eec\u5982\u4f55\u590d\u7528\u7ebf\u7a0b?<\/li>\n<li>\u6211\u4eec\u6307\u5b9a\u4e86\u7ebf\u7a0b\u7684\u6700\u5927\u6570\u91cf\uff0c\u5f53\u4efb\u52a1\u6570\u8d85\u51fa\u7ebf\u7a0b\u6570\u65f6\uff0c\u6211\u4eec\u8be5\u5982\u4f55\u5904\u7406?<\/li>\n<\/ol>\n<h4>1.3\u3001\u521b\u65b0\u6e90\u4e8e\u751f\u6d3b<\/h4>\n<p>\u5148\u5047\u8bbe\u4e00\u4e2a\u573a\u666f:\u5047\u8bbe\u6211\u4eec\u662f\u4e00\u4e2a\u7269\u6d41\u516c\u53f8\u7684\u7ba1\u7406\u4eba\u5458\uff0c\u8981\u914d\u9001\u7684\u8d27\u7269\u5c31\u662f\u6211\u4eec\u7684\u4efb\u52a1\uff0c\u8d27\u8f66\u5c31\u662f \u6211\u4eec\u914d\u9001\u5de5\u5177\uff0c\u6211\u4eec\u5f53\u7136\u4e0d\u80fd\u6709\u591a\u5c11\u8d27\u7269\u5c31\u51c6\u5907\u591a\u5c11\u8d27\u8f66\u3002\u90a3\u5f53\u987e\u5ba2\u6e90\u6e90\u4e0d\u65ad\u7684\u5c06\u8d27\u7269\u4ea4\u7ed9\u6211\u4eec\u914d \u9001\uff0c\u6211\u4eec\u8be5\u5982\u4f55\u7ba1\u7406\u624d\u80fd\u8ba9\u516c\u53f8\u7ecf\u8425\u7684\u6700\u597d\u5462?<\/p>\n<ol>\n<li>\u6700\u5f00\u59cb\u8d27\u7269\u6765\u7684\u65f6\u5019\uff0c\u6211\u4eec\u8fd8\u6ca1\u6709\u8d27\u8f66\uff0c\u6bcf\u6279\u8981\u8fd0\u8f93\u7684\u8d27\u7269\u6211\u4eec\u90fd\u8981\u8d2d\u4e70\u4e00\u8f86\u8f66\u6765\u8fd0\u8f93;<\/li>\n<li>\u5f53\u8d27\u8f66\u8fd0\u8f93\u5b8c\u6210\u540e\uff0c\u6682\u65f6\u8fd8\u6ca1\u6709\u4e0b\u4e00\u6279\u8d27\u7269\u5230\u8fbe\uff0c\u90a3\u8d27\u8f66\u5c31\u5728\u4ed3\u5e93\u505c\u7740\uff0c\u7b49\u6709\u8d27\u7269\u6765\u4e86\u7acb\u9a6c\u5c31\u53ef\u4ee5 \u8fd0\u8f93;<\/li>\n<li>\u5f53\u6211\u4eec\u6709\u4e86\u4e00\u5b9a\u6570\u91cf\u7684\u8f66\u540e\uff0c\u6211\u4eec\u8ba4\u4e3a\u5df2\u7ecf\u591f\u7528\u4e86\uff0c\u90a3\u540e\u9762\u5c31\u4e0d\u518d\u4e70\u8f66\u4e86\uff0c\u8fd9\u65f6\u8981\u662f\u7531\u65b0\u7684\u8d27\u7269\u6765 \u4e86\uff0c\u6211\u4eec\u5c31\u4f1a\u8ba9\u8d27\u7269\u5148\u653e\u4ed3\u5e93\uff0c\u7b49\u6709\u8f66\u56de\u6765\u5728\u914d\u9001;<\/li>\n<li>\u5f53618\u5927\u4fc3\u6765\u88ad\uff0c\u8981\u914d\u9001\u7684\u8d27\u7269\u592a\u591a\uff0c\u8f66\u90fd\u5728\u8def\u4e0a\uff0c\u4ed3\u5e93\u4e5f\u90fd\u653e\u6ee1\u4e86\uff0c\u90a3\u600e\u4e48\u529e\u5462?\u6211\u4eec\u5c31\u9009\u62e9\u4e34 \u65f6\u79df\u4e00\u4e9b\u8f66\u6765\u5e2e\u5fd9\u914d\u9001\uff0c\u63d0\u9ad8\u914d\u9001\u7684\u6548\u7387;<\/li>\n<li>\u4f46\u662f\u8d27\u7269\u8fd8\u662f\u592a\u591a\uff0c\u6211\u4eec\u589e\u52a0\u4e86\u4e34\u65f6\u7684\u8d27\u8f66\uff0c\u4f9d\u65e7\u914d\u9001\u4e0d\u8fc7\u6765\uff0c\u90a3\u8fd9\u65f6\u6211\u4eec\u5c31\u6ca1\u529e\u6cd5\u4e86\uff0c\u53ea\u80fd\u8ba9\u53d1 \u8d27\u7684\u5ba2\u6237\u6392\u961f\u7b49\u5019\u6216\u8005\u5e72\u8106\u4e0d\u63a5\u53d7\u4e86;<\/li>\n<li>\u5927\u4fc3\u5706\u6ee1\u5b8c\u6210\u540e\uff0c\u7d2f\u8ba1\u7684\u8d27\u7269\u5df2\u7ecf\u914d\u9001\u5b8c\u6210\u4e86\uff0c\u4e3a\u4e86\u964d\u4f4e\u6210\u672c\uff0c\u6211\u4eec\u5c31\u5c06\u4e34\u65f6\u79df\u7684\u8f66\u90fd\u8fd8\u4e86;<\/li>\n<\/ol>\n<h4>1.4\u3001\u6280\u672f\u6e90\u4e8e\u521b\u65b0<\/h4>\n<p>\u57fa\u4e8e\u4e0a\u8ff0\u573a\u666f\uff0c\u7269\u6d41\u516c\u53f8\u5c31\u662f\u6211\u4eec\u7684\u7ebf\u7a0b\u6c60\u3001\u8d27\u7269\u5c31\u662f\u6211\u4eec\u7684\u7ebf\u7a0b\u4efb\u52a1\u3001\u8d27\u8f66\u5c31\u662f\u6211\u4eec\u7684\u7ebf\u7a0b\u3002\u6211 \u4eec\u5982\u4f55\u8bbe\u8ba1\u516c\u53f8\u7684\u7ba1\u7406\u8d27\u8f66\u7684\u6d41\u7a0b\uff0c\u5c31\u5e94\u8be5\u5982\u4f55\u8bbe\u8ba1\u7ebf\u7a0b\u6c60\u7ba1\u7406\u7ebf\u7a0b\u7684\u6d41\u7a0b\u3002<\/p>\n<ol>\n<li>\u5f53\u4efb\u52a1\u8fdb\u6765\u6211\u4eec\u8fd8\u6ca1\u6709\u7ebf\u7a0b\u65f6\uff0c\u6211\u4eec\u5c31\u8be5\u521b\u5efa\u7ebf\u7a0b\u6267\u884c\u4efb\u52a1;<\/li>\n<li>\u5f53\u7ebf\u7a0b\u4efb\u52a1\u6267\u884c\u5b8c\u6210\u540e\uff0c\u7ebf\u7a0b\u4e0d\u91ca\u653e\uff0c\u7b49\u7740\u4e0b\u4e00\u4e2a\u4efb\u52a1\u8fdb\u6765\u540e\u63a5\u7740\u6267\u884c;<\/li>\n<li>\u5f53\u521b\u5efa\u7684\u7ebf\u7a0b\u6570\u91cf\u8fbe\u5230\u4e00\u5b9a\u91cf\u540e\uff0c\u65b0\u6765\u7684\u4efb\u52a1\u6211\u4eec\u5b58\u8d77\u6765\u7b49\u5f85\u7a7a\u95f2\u7ebf\u7a0b\u6267\u884c\uff0c\u8fd9\u5c31\u8981\u6c42\u7ebf\u7a0b\u6c60\u6709\u4e2a \u5b58\u4efb\u52a1\u7684\u5bb9\u5668;<\/li>\n<li>\u5f53\u5bb9\u5668\u5b58\u6ee1\u540e\uff0c\u6211\u4eec\u9700\u8981\u589e\u52a0\u4e00\u4e9b\u4e34\u65f6\u7684\u7ebf\u7a0b\u6765\u63d0\u9ad8\u5904\u7406\u6548\u7387;<\/li>\n<li>\u5f53\u589e\u52a0\u4e34\u65f6\u7ebf\u7a0b\u540e\u4f9d\u65e7\u5904\u7406\u4e0d\u4e86\u7684\u4efb\u52a1\uff0c\u90a3\u5c31\u5e94\u8be5\u5c06\u6b64\u4efb\u52a1\u62d2\u7edd;<\/li>\n<li>\u5f53\u6240\u6709\u4efb\u52a1\u6267\u884c\u5b8c\u6210\u540e\uff0c\u5c31\u5e94\u8be5\u5c06\u4e34\u65f6\u7684\u7ebf\u7a0b\u91ca\u653e\u6389\uff0c\u4ee5\u514d\u589e\u52a0\u4e0d\u5fc5\u8981\u7684\u5f00\u9500;<\/li>\n<\/ol>\n<h3>2\u3001\u7ebf\u7a0b\u6c60\u5177\u4f53\u5206\u6790<\/h3>\n<p>\u4e0a\u6587\u4e2d\uff0c\u6211\u4eec\u8bb2\u4e86\u8be5\u5982\u4f55\u8bbe\u8ba1\u4e00\u4e2a\u7ebf\u7a0b\u6c60\uff0c\u4e0b\u9762\u6211\u4eec\u770b\u770b\u5927\u795e\u662f\u5982\u4f55\u8bbe\u8ba1\u7684\uff1b<\/p>\n<h4>2.1\u3001 JAVA\u4e2d\u7684\u7ebf\u7a0b\u6c60\u662f\u5982\u4f55\u8bbe\u8ba1\u7684<\/h4>\n<h5>2.1.1\u3001 \u7ebf\u7a0b\u6c60\u8bbe\u8ba1<\/h5>\n<p>\u770b\u4e0b\u7ebf\u7a0b\u6c60\u4e2d\u7684\u5c5e\u6027\uff0c\u4e86\u89e3\u7ebf\u7a0b\u6c60\u7684\u8bbe\u8ba1\u3002<\/p>\n<pre><code>public class ThreadPoolExecutor extends AbstractExecutorService {\n\n    \/\/\u7ebf\u7a0b\u6c60\u7684\u6253\u5305\u63a7\u5236\u72b6\u6001,\u7528\u9ad83\u4f4d\u6765\u8868\u793a\u7ebf\u7a0b\u6c60\u7684\u8fd0\u884c\u72b6\u6001,\u4f4e29\u4f4d\u6765\u8868\u793a\u7ebf\u7a0b\u6c60\u4e2d\u5de5\u4f5c\u7ebf\u7a0b\u7684\u6570\u91cf \n    private final AtomicInteger ctl = new AtomicInteger(ctlOf(RUNNING, 0)); \n    \n    \/\/\u503c\u4e3a29,\u7528\u6765\u8868\u793a\u504f\u79fb\u91cf\n     private static final int COUNT_BITS = Integer.SIZE - 3; \n\n    \/\/\u7ebf\u7a0b\u6c60\u7684\u6700\u5927\u5bb9\u91cf\n     private static final int CAPACITY = (1 &lt;&lt; COUNT_BITS) - 1; \n\n    \/\/\u7ebf\u7a0b\u6c60\u7684\u8fd0\u884c\u72b6\u6001\uff0c\u603b\u5171\u67095\u4e2a\u72b6\u6001\uff0c\u7528\u9ad83\u4f4d\u6765\u8868\u793a \n    private static final int RUNNING = -1 &lt;&lt; COUNT_BITS;  \/\/\u63a5\u53d7\u65b0\u4efb\u52a1\u5e76\u5904\u7406\u963b\u585e\u961f\u5217\u4e2d\u7684\u4efb\u52a1 \n\n    private static final int SHUTDOWN = 0 &lt;&lt; COUNT_BITS;  \/\/\u4e0d\u63a5\u53d7\u65b0\u4efb\u52a1\u4f46\u4f1a\u5904\u7406\u963b\u585e\u961f\u5217\u4e2d\u7684\u4efb\u52a1  \n\n    private static final int STOP = 1 &lt;&lt; COUNT_BITS;  \/\/\u4e0d\u4f1a\u63a5\u53d7\u65b0\u4efb\u52a1\uff0c\u4e5f\u4e0d\u4f1a\u5904\u7406\u963b\u585e\u961f\u5217\u4e2d\u7684\u4efb\u52a1\uff0c\u5e76\u4e14\u4e2d\u65ad\u6b63\u5728\u8fd0\u884c\u7684\u4efb\u52a1\n\n    private static final int TIDYING = 2 &lt;&lt; COUNT_BITS;  \/\/\u6240\u6709\u4efb\u52a1\u90fd\u5df2\u7ec8\u6b62\uff0c \u5de5\u4f5c\u7ebf\u7a0b\u6570\u91cf\u4e3a0\uff0c\u5373\u5c06\u8981\u6267\u884cterminated()\u94a9\u5b50\u65b9\u6cd5 \n\n    private static final int TERMINATED =  3 &lt;&lt; COUNT_BITS;  \/\/ terminated()\u65b9\u6cd5\u5df2\u7ecf\u6267\u884c\u7ed3\u675f\n\n    \/\/\u4efb\u52a1\u7f13\u5b58\u961f\u5217\uff0c\u7528\u6765\u5b58\u653e\u7b49\u5f85\u6267\u884c\u7684\u4efb\u52a1\n    private final BlockingQueue&lt;Runnable&gt; workQueue; \n\n    \/\/\u5168\u5c40\u9501\uff0c\u5bf9\u7ebf\u7a0b\u6c60\u72b6\u6001\u7b49\u5c5e\u6027\u4fee\u6539\u65f6\u9700\u8981\u4f7f\u7528\u8fd9\u4e2a\u9501\n    private final ReentrantLock mainLock = new ReentrantLock(); \n\n    \/\/\u7ebf\u7a0b\u6c60\u4e2d\u5de5\u4f5c\u7ebf\u7a0b\u7684\u96c6\u5408\uff0c\u8bbf\u95ee\u548c\u4fee\u6539\u9700\u8981\u6301\u6709\u5168\u5c40\u9501\n    private final HashSet&lt;Worker&gt; workers = new HashSet&lt;Worker&gt;(); \n\n    \/\/ \u7ec8\u6b62\u6761\u4ef6\n    private final Condition termination = mainLock.newCondition(); \n\n    \/\/\u7ebf\u7a0b\u6c60\u4e2d\u66fe\u7ecf\u51fa\u73b0\u8fc7\u7684\u6700\u5927\u7ebf\u7a0b\u6570 \n    private int largestPoolSize; \n    \n    \/\/\u5df2\u5b8c\u6210\u4efb\u52a1\u7684\u6570\u91cf\n    private long completedTaskCount; \n    \n    \/\/\u7ebf\u7a0b\u5de5\u5382\n    private volatile ThreadFactory threadFactory; \n    \n    \/\/\u4efb\u52a1\u62d2\u7edd\u7b56\u7565\n    private volatile RejectedExecutionHandler handler; \n\n    \/\/\u7ebf\u7a0b\u5b58\u6d3b\u65f6\u95f4\n    private volatile long keepAliveTime; \n\n    \/\/\u662f\u5426\u5141\u8bb8\u6838\u5fc3\u7ebf\u7a0b\u8d85\u65f6\n    private volatile boolean allowCoreThreadTimeOut; \n\n    \/\/\u6838\u5fc3\u6c60\u5927\u5c0f\uff0c\u82e5allowCoreThreadTimeOut\u88ab\u8bbe\u7f6e\uff0c\u6838\u5fc3\u7ebf\u7a0b\u5168\u90e8\u7a7a\u95f2\u8d85\u65f6\u88ab\u56de\u6536\u7684\u60c5\u51b5\u4e0b\u4f1a\u4e3a0 \n    private volatile int corePoolSize; \n\n    \/\/\u6700\u5927\u6c60\u5927\u5c0f\uff0c\u4e0d\u5f97\u8d85\u8fc7CAPACITY\n    private volatile int maximumPoolSize; \n    \n    \/\/\u9ed8\u8ba4\u7684\u4efb\u52a1\u62d2\u7edd\u7b56\u7565\n    private static final RejectedExecutionHandler defaultHandler = new AbortPolicy();\n\n    \/\/\u8fd0\u884c\u6743\u9650\u76f8\u5173\n    private static final RuntimePermission shutdownPerm = \n        new RuntimePermission(&quot;modifyThread&quot;);\n\n    ... \n} \n<\/code><\/pre>\n<p>\u5c0f\u7ed3\u4e00\u4e0b\uff1a\u4ee5\u4e0a\u7ebf\u7a0b\u6c60\u7684\u8bbe\u8ba1\u53ef\u4ee5\u770b\u51fa\uff0c\u7ebf\u7a0b\u6c60\u7684\u529f\u80fd\u8fd8\u662f\u5f88\u5b8c\u5584\u7684\u3002<\/p>\n<ol>\n<li>\u63d0\u4f9b\u4e86\u7ebf\u7a0b\u521b\u5efa\u3001\u6570\u91cf\u53ca\u5b58\u6d3b\u65f6\u95f4\u7b49\u7684\u7ba1\u7406;<\/li>\n<li>\u63d0\u4f9b\u4e86\u7ebf\u7a0b\u6c60\u72b6\u6001\u6d41\u8f6c\u7684\u7ba1\u7406;<\/li>\n<li>\u63d0\u4f9b\u4e86\u4efb\u52a1\u7f13\u5b58\u7684\u5404\u79cd\u5bb9\u5668;<\/li>\n<li>\u63d0\u4f9b\u4e86\u591a\u4f59\u4efb\u52a1\u7684\u5904\u7406\u673a\u5236;<\/li>\n<li>\u63d0\u4f9b\u4e86\u7b80\u5355\u7684\u7edf\u8ba1\u529f\u80fd;<\/li>\n<\/ol>\n<h5>2.1.2\u3001\u7ebf\u7a0b\u6c60\u6784\u9020\u51fd\u6570<\/h5>\n<pre><code>\/\/\u6784\u9020\u51fd\u6570\n public ThreadPoolExecutor(int corePoolSize, \/\/\u6838\u5fc3\u7ebf\u7a0b\u6570 \n                           int maximumPoolSize, \/\/\u6700\u5927\u5141\u8bb8\u7ebf\u7a0b\u6570 \n                           long keepAliveTime, \/\/\u7ebf\u7a0b\u5b58\u6d3b\u65f6\u95f4 \n                           TimeUnit unit, \/\/\u5b58\u6d3b\u65f6\u95f4\u5355\u4f4d \n                           BlockingQueue&lt;Runnable&gt; workQueue, \/\/\u4efb\u52a1\u7f13\u5b58\u961f\u5217\n                           ThreadFactory threadFactory, \/\/\u7ebf\u7a0b\u5de5\u5382 \n                           RejectedExecutionHandler handler) { \/\/\u62d2\u7edd\u7b56\u7565 \n    if (corePoolSize &lt; 0 ||\n        maximumPoolSize &lt;= 0 ||\n        maximumPoolSize &lt; corePoolSize ||\n        keepAliveTime &lt; 0)\n        throw new IllegalArgumentException();\n        \n    if (workQueue == null || threadFactory == null || handler == null)\n        throw new NullPointerException();\n        \n    this.corePoolSize = corePoolSize;\n    this.maximumPoolSize = maximumPoolSize;\n    this.workQueue = workQueue;\n    this.keepAliveTime = unit.toNanos(keepAliveTime);\n    this.threadFactory = threadFactory;\n    this.handler = handler;\n} \n<\/code><\/pre>\n<p>\u5c0f\u7ed3\u4e00\u4e0b\uff1a<\/p>\n<ol>\n<li>\u6784\u9020\u51fd\u6570\u544a\u8bc9\u4e86\u6211\u4eec\u53ef\u4ee5\u600e\u6837\u53bb\u9002\u7528\u7ebf\u7a0b\u6c60\uff0c\u7ebf\u7a0b\u6c60\u7684\u54ea\u4e9b\u7279\u6027\u662f\u6211\u4eec\u53ef\u4ee5\u63a7\u5236\u7684;<\/li>\n<\/ol>\n<h5>2.1.3\u3001\u7ebf\u7a0b\u6c60\u6267\u884c<\/h5>\n<p>2.1.3.1\u3001\u63d0\u4ea4\u4efb\u52a1\u65b9\u6cd5<\/p>\n<p>\u2022 public void execute(Runnable command);<\/p>\n<p>\u2022 Future&lt;?&gt; submit(Runnable task);<\/p>\n<p>\u2022 Future submit(Runnable task, T result);<\/p>\n<p>\u2022 Future submit(Callable task);<\/p>\n<pre><code>public Future&lt;?&gt; submit(Runnable task) {\n        if (task == null) throw new NullPointerException();\n        RunnableFuture&lt;Void&gt; ftask = newTaskFor(task, null);\n        execute(ftask);\n        return ftask;\n}\n<\/code><\/pre>\n<p>\u53ef\u4ee5\u770b\u5230submit\u65b9\u6cd5\u7684\u5e95\u5c42\u8c03\u7528\u7684\u4e5f\u662fexecute\u65b9\u6cd5\uff0c\u6240\u4ee5\u6211\u4eec\u8fd9\u91cc\u53ea\u5206\u6790execute\u65b9\u6cd5\uff1b<\/p>\n<pre><code>    public void execute(Runnable command) {\n        if (command == null)\n            throw new NullPointerException();\n        \n        int c = ctl.get();\n        \/\/\u7b2c\u4e00\u6b65\uff1a\u521b\u5efa\u6838\u5fc3\u7ebf\u7a0b\n        if (workerCountOf(c) &lt; corePoolSize) {  \/\/worker\u6570\u91cf\u5c0f\u4e8ecorePoolSize\n            if (addWorker(command, true))       \/\/\u521b\u5efaworker\n                return;\n            c = ctl.get();\n        }\n        \/\/\u7b2c\u4e8c\u6b65\uff1a\u52a0\u5165\u7f13\u5b58\u961f\u5217\n        if (isRunning(c) &amp;&amp; workQueue.offer(command)) { \/\/\u7ebf\u7a0b\u6c60\u5904\u4e8eRUNNING\u72b6\u6001\uff0c\u5c06\u4efb\u52a1\u52a0\u5165workQueue\u4efb\u52a1\u7f13\u5b58\u961f\u5217\n            int recheck = ctl.get();    \n            if (! isRunning(recheck) &amp;&amp; remove(command))    \/\/\u53cc\u91cd\u68c0\u67e5\uff0c\u82e5\u7ebf\u7a0b\u6c60\u72b6\u6001\u5173\u95ed\u4e86\uff0c\u79fb\u9664\u4efb\u52a1\n                reject(command);\n            else if (workerCountOf(recheck) == 0)       \/\/\u7ebf\u7a0b\u6c60\u72b6\u6001\u6b63\u5e38\uff0c\u4f46\u662f\u6ca1\u6709\u7ebf\u7a0b\u4e86\uff0c\u521b\u5efaworker\n                addWorker(null, false);\n        }\n        \/\/\u7b2c\u4e09\u6b65\uff1a\u521b\u5efa\u4e34\u65f6\u7ebf\u7a0b\n        else if (!addWorker(command, false))\n            reject(command);\n    }\n<\/code><\/pre>\n<p>\u5c0f\u7ed3\u4e00\u4e0b\uff1aexecute()\u65b9\u6cd5\u4e3b\u8981\u529f\u80fd\uff1a<\/p>\n<ol>\n<li>\u6838\u5fc3\u7ebf\u7a0b\u6570\u91cf\u4e0d\u8db3\u5c31\u521b\u5efa\u6838\u5fc3\u7ebf\u7a0b\uff1b<\/li>\n<li>\u6838\u5fc3\u7ebf\u7a0b\u6ee1\u4e86\u5c31\u52a0\u5165\u7f13\u5b58\u961f\u5217\uff1b<\/li>\n<li>\u7f13\u5b58\u961f\u5217\u6ee1\u4e86\u5c31\u589e\u52a0\u975e\u6838\u5fc3\u7ebf\u7a0b\uff1b<\/li>\n<li>\u975e\u6838\u5fc3\u7ebf\u7a0b\u4e5f\u6ee1\u4e86\u5c31\u62d2\u7edd\u4efb\u52a1\uff1b<\/li>\n<\/ol>\n<p>2.1.3.2\u3001\u521b\u5efa\u7ebf\u7a0b<\/p>\n<pre><code>private boolean addWorker(Runnable firstTask, boolean core) {\n        retry:\n        for (;;) {\n            int c = ctl.get();\n            int rs = runStateOf(c);\n\u200b\n            \/\/\u7b49\u4ef7\u4e8e\uff1ars&gt;=SHUTDOWN &amp;&amp; (rs != SHUTDOWN || firstTask != null || workQueue.isEmpty())\n            \/\/\u7ebf\u7a0b\u6c60\u5df2\u5173\u95ed\uff0c\u5e76\u4e14\u65e0\u9700\u6267\u884c\u7f13\u5b58\u961f\u5217\u4e2d\u7684\u4efb\u52a1\uff0c\u5219\u4e0d\u521b\u5efa\n            if (rs &gt;= SHUTDOWN &amp;&amp;\n                ! (rs == SHUTDOWN &amp;&amp;\n                   firstTask == null &amp;&amp;\n                   ! workQueue.isEmpty()))\n                return false;\n\u200b\n            for (;;) {\n                int wc = workerCountOf(c);\n                if (wc &gt;= CAPACITY ||\n                    wc &gt;= (core ? corePoolSize : maximumPoolSize))\n                    return false;\n                if (compareAndIncrementWorkerCount(c))  \/\/CAS\u589e\u52a0\u7ebf\u7a0b\u6570\n                    break retry;\n                c = ctl.get();  \/\/ Re-read ctl\n                if (runStateOf(c) != rs)\n                    continue retry;\n                \/\/ else CAS failed due to workerCount change; retry inner loop\n            }\n        }\n\u200b\n        \/\/\u4e0a\u9762\u7684\u6d41\u7a0b\u8d70\u5b8c\uff0c\u5c31\u53ef\u4ee5\u771f\u5b9e\u5f00\u59cb\u521b\u5efa\u7ebf\u7a0b\u4e86\n        boolean workerStarted = false;\n        boolean workerAdded = false;\n        Worker w = null;\n        try {\n            w = new Worker(firstTask);  \/\/\u8fd9\u91cc\u521b\u5efa\u4e86\u7ebf\u7a0b\n            final Thread t = w.thread;\n            if (t != null) {\n                final ReentrantLock mainLock = this.mainLock;\n                mainLock.lock();\n                try {\n                    \/\/ Recheck while holding lock.\n                    \/\/ Back out on ThreadFactory failure or if\n                    \/\/ shut down before lock acquired.\n                    int rs = runStateOf(ctl.get());\n\u200b\n                    if (rs &lt; SHUTDOWN ||\n                        (rs == SHUTDOWN &amp;&amp; firstTask == null)) {\n                        if (t.isAlive()) \/\/ precheck that t is startable\n                            throw new IllegalThreadStateException();\n                        workers.add(w);     \/\/\u8fd9\u91cc\u5c06\u7ebf\u7a0b\u52a0\u5165\u5230\u7ebf\u7a0b\u6c60\u4e2d\n                        int s = workers.size();\n                        if (s &gt; largestPoolSize)\n                            largestPoolSize = s;\n                        workerAdded = true;\n                    }\n                } finally {\n                    mainLock.unlock();\n                }\n                if (workerAdded) {\n                    t.start();      \/\/\u6dfb\u52a0\u6210\u529f\uff0c\u542f\u52a8\u7ebf\u7a0b\n                    workerStarted = true;\n                }\n            }\n        } finally {\n            if (! workerStarted)\n                addWorkerFailed(w);     \/\/\u6dfb\u52a0\u7ebf\u7a0b\u5931\u8d25\u64cd\u4f5c\n        }\n        return workerStarted;\n    }\n<\/code><\/pre>\n<p>\u5c0f\u7ed3\uff1aaddWorker()\u65b9\u6cd5\u4e3b\u8981\u529f\u80fd\uff1b<\/p>\n<ol>\n<li>\u589e\u52a0\u7ebf\u7a0b\u6570\uff1b<\/li>\n<li>\u521b\u5efa\u7ebf\u7a0bWorker\u5b9e\u4f8b\u52a0\u5165\u7ebf\u7a0b\u6c60\uff1b<\/li>\n<li>\u52a0\u5165\u5b8c\u6210\u5f00\u542f\u7ebf\u7a0b\uff1b<\/li>\n<li>\u542f\u52a8\u5931\u8d25\u5219\u56de\u6eda\u589e\u52a0\u6d41\u7a0b\uff1b<\/li>\n<\/ol>\n<p>2.1.3.3\u3001\u5de5\u4f5c\u7ebf\u7a0b\u7684\u5b9e\u73b0<\/p>\n<pre><code>    private final class Worker  \/\/Worker\u7c7b\u662fThreadPoolExecutor\u7684\u5185\u90e8\u7c7b\n        extends AbstractQueuedSynchronizer  \n        implements Runnable\n    {\n        \n        final Thread thread;    \/\/\u6301\u6709\u5b9e\u9645\u7ebf\u7a0b\n        Runnable firstTask;     \/\/worker\u6240\u5bf9\u5e94\u7684\u7b2c\u4e00\u4e2a\u4efb\u52a1\uff0c\u53ef\u80fd\u4e3a\u7a7a\n        volatile long completedTasks;   \/\/\u8bb0\u5f55\u6267\u884c\u4efb\u52a1\u6570\n\u200b\n        Worker(Runnable firstTask) {\n            setState(-1); \/\/ inhibit interrupts until runWorker\n            this.firstTask = firstTask;\n            this.thread = getThreadFactory().newThread(this);\n        }\n        \n        public void run() {\n            runWorker(this);    \/\/\u5f53\u524d\u7ebf\u7a0b\u8c03\u7528ThreadPoolExecutor\u4e2d\u7684runWorker\u65b9\u6cd5\uff0c\u5728\u8fd9\u91cc\u5b9e\u73b0\u7684\u7ebf\u7a0b\u590d\u7528\n        }\n\u200b\n        ...\u7ee7\u627fAQS\uff0c\u5b9e\u73b0\u4e86\u4e0d\u53ef\u91cd\u5165\u9501...\n    }\n<\/code><\/pre>\n<p>\u5c0f\u7ed3\uff1a\u5de5\u4f5c\u7ebf\u7a0bWorker\u7c7b\u4e3b\u8981\u529f\u80fd\uff1b<\/p>\n<ol>\n<li>\u6b64\u7c7b\u6301\u6709\u4e00\u4e2a\u5de5\u4f5c\u7ebf\u7a0b\uff0c\u4e0d\u65ad\u5904\u7406\u62ff\u5230\u7684\u65b0\u4efb\u52a1\uff0c\u6301\u6709\u7684\u7ebf\u7a0b\u5373\u4e3a\u53ef\u590d\u7528\u7684\u7ebf\u7a0b\uff1b<\/li>\n<li>\u6b64\u7c7b\u53ef\u770b\u4f5c\u4e00\u4e2a\u9002\u914d\u7c7b\uff0c\u5728run()\u65b9\u6cd5\u4e2d\u771f\u5b9e\u8c03\u7528runWorker()\u65b9\u6cd5\u4e0d\u65ad\u83b7\u53d6\u65b0\u4efb\u52a1\uff0c\u5b8c\u6210\u7ebf\u7a0b\u590d\u7528\uff1b<\/li>\n<\/ol>\n<p>2.1.3.4\u3001\u7ebf\u7a0b\u7684\u590d\u7528<\/p>\n<pre><code>    final void runWorker(Worker w) {    \/\/ThreadPoolExecutor\u4e2d\u7684runWorker\u65b9\u6cd5\uff0c\u5728\u8fd9\u91cc\u5b9e\u73b0\u7684\u7ebf\u7a0b\u590d\u7528\n        Thread wt = Thread.currentThread();\n        Runnable task = w.firstTask;\n        w.firstTask = null;\n        w.unlock(); \/\/ allow interrupts\n        boolean completedAbruptly = true;   \/\/\u6807\u8bc6\u7ebf\u7a0b\u662f\u5426\u5f02\u5e38\u7ec8\u6b62\n        try {\n            while (task != null || (task = getTask()) != null) {    \/\/\u8fd9\u91cc\u4f1a\u4e0d\u65ad\u4ece\u4efb\u52a1\u961f\u5217\u83b7\u53d6\u4efb\u52a1\u5e76\u6267\u884c\n                w.lock();\n                \n                \/\/\u7ebf\u7a0b\u662f\u5426\u9700\u8981\u4e2d\u65ad\n                if ((runStateAtLeast(ctl.get(), STOP) ||    \n                     (Thread.interrupted() &amp;&amp;\n                      runStateAtLeast(ctl.get(), STOP))) &amp;&amp;\n                    !wt.isInterrupted())\n                    wt.interrupt();\n                try {\n                    beforeExecute(wt, task);    \/\/\u6267\u884c\u4efb\u52a1\u524d\u7684Hook\u65b9\u6cd5\uff0c\u53ef\u81ea\u5b9a\u4e49\n                    Throwable thrown = null;\n                    try {\n                        task.run();             \/\/\u6267\u884c\u5b9e\u9645\u7684\u4efb\u52a1\n                    } catch (RuntimeException x) {\n                        thrown = x; throw x;\n                    } catch (Error x) {\n                        thrown = x; throw x;\n                    } catch (Throwable x) {\n                        thrown = x; throw new Error(x);\n                    } finally {\n                        afterExecute(task, thrown); \/\/\u6267\u884c\u4efb\u52a1\u540e\u7684Hook\u65b9\u6cd5\uff0c\u53ef\u81ea\u5b9a\u4e49\n                    }\n                } finally {\n                    task = null;    \/\/\u6267\u884c\u5b8c\u6210\u540e\uff0c\u5c06\u5f53\u524d\u7ebf\u7a0b\u4e2d\u7684\u4efb\u52a1\u5236\u7a7a\uff0c\u51c6\u5907\u6267\u884c\u4e0b\u4e00\u4e2a\u4efb\u52a1\n                    w.completedTasks++;\n                    w.unlock();\n                }\n            }\n            completedAbruptly = false;\n        } finally {\n            processWorkerExit(w, completedAbruptly);    \/\/\u7ebf\u7a0b\u6267\u884c\u5b8c\u6210\u540e\u7684\u6e05\u7406\u5de5\u4f5c\n        }\n    }\n<\/code><\/pre>\n<p>\u5c0f\u7ed3\uff1arunWorker()\u65b9\u6cd5\u4e3b\u8981\u529f\u80fd\uff1b<\/p>\n<ol>\n<li>\u5faa\u73af\u4ece\u7f13\u5b58\u961f\u5217\u4e2d\u83b7\u53d6\u65b0\u7684\u4efb\u52a1\uff0c\u76f4\u5230\u6ca1\u6709\u4efb\u52a1\u4e3a\u6b62\uff1b<\/li>\n<li>\u4f7f\u7528worker\u6301\u6709\u7684\u7ebf\u7a0b\u771f\u5b9e\u6267\u884c\u4efb\u52a1\uff1b<\/li>\n<li>\u4efb\u52a1\u90fd\u6267\u884c\u5b8c\u6210\u540e\u7684\u6e05\u7406\u5de5\u4f5c\uff1b<\/li>\n<\/ol>\n<p>2.1.3.5\u3001\u961f\u5217\u4e2d\u83b7\u53d6\u5f85\u6267\u884c\u4efb\u52a1<\/p>\n<pre><code>    private Runnable getTask() {\n        boolean timedOut = false;   \/\/\u6807\u8bc6\u5f53\u524d\u7ebf\u7a0b\u662f\u5426\u8d85\u65f6\u672a\u80fd\u83b7\u53d6\u5230task\u5bf9\u8c61\n\u200b\n        for (;;) {\n            int c = ctl.get();\n            int rs = runStateOf(c);\n\u200b\n            \/\/ Check if queue empty only if necessary.\n            if (rs &gt;= SHUTDOWN &amp;&amp; (rs &gt;= STOP || workQueue.isEmpty())) {\n                decrementWorkerCount();\n                return null;\n            }\n\u200b\n            int wc = workerCountOf(c);\n\u200b\n            \/\/ Are workers subject to culling?\n            boolean timed = allowCoreThreadTimeOut || wc &gt; corePoolSize;\n\u200b\n            if ((wc &gt; maximumPoolSize || (timed &amp;&amp; timedOut))\n                &amp;&amp; (wc &gt; 1 || workQueue.isEmpty())) {\n                if (compareAndDecrementWorkerCount(c))      \/\/\u82e5\u7ebf\u7a0b\u5b58\u6d3b\u65f6\u95f4\u8d85\u65f6\uff0c\u5219CAS\u51cf\u53bb\u7ebf\u7a0b\u6570\u91cf\n                    return null;\n                continue;\n            }\n\u200b\n            try {\n                Runnable r = timed ?\n                    workQueue.poll(keepAliveTime, TimeUnit.NANOSECONDS) :   \/\/\u5141\u8bb8\u8d85\u65f6\u56de\u6536\u5219\u963b\u585e\u7b49\u5f85\n                    workQueue.take();                                   \/\/\u4e0d\u5141\u8bb8\u5219\u76f4\u63a5\u83b7\u53d6\uff0c\u6ca1\u6709\u5c31\u8fd4\u56denull\n                if (r != null)\n                    return r;\n                timedOut = true;\n            } catch (InterruptedException retry) {\n                timedOut = false;\n            }\n        }\n    }\n<\/code><\/pre>\n<p>\u5c0f\u7ed3\uff1agetTask()\u65b9\u6cd5\u4e3b\u8981\u529f\u80fd\uff1b<\/p>\n<ol>\n<li>\u5b9e\u9645\u5728\u7f13\u5b58\u961f\u5217\u4e2d\u83b7\u53d6\u5f85\u6267\u884c\u7684\u4efb\u52a1\uff1b<\/li>\n<li>\u5728\u8fd9\u91cc\u7ba1\u7406\u7ebf\u7a0b\u662f\u5426\u8981\u963b\u585e\u7b49\u5f85\uff0c\u63a7\u5236\u7ebf\u7a0b\u7684\u6570\u91cf\uff1b<\/li>\n<\/ol>\n<p>2.1.3.6\u3001\u6e05\u7406\u5de5\u4f5c<\/p>\n<pre><code>  private void processWorkerExit(Worker w, boolean completedAbruptly) {\n        if (completedAbruptly) \/\/ If abrupt, then workerCount wasn't adjusted\n            decrementWorkerCount();\n\u200b\n        final ReentrantLock mainLock = this.mainLock;\n        mainLock.lock();\n        try {\n            completedTaskCount += w.completedTasks;\n            workers.remove(w);          \/\/\u79fb\u9664\u6267\u884c\u5b8c\u6210\u7684\u7ebf\u7a0b\n        } finally {\n            mainLock.unlock();\n        }\n\u200b\n        tryTerminate();     \/\/\u6bcf\u6b21\u56de\u6536\u5b8c\u4e00\u4e2a\u7ebf\u7a0b\u540e\u90fd\u5c1d\u8bd5\u7ec8\u6b62\u7ebf\u7a0b\u6c60\n\u200b\n        int c = ctl.get();\n        if (runStateLessThan(c, STOP)) {    \/\/\u5230\u8fd9\u91cc\u8bf4\u660e\u7ebf\u7a0b\u6c60\u6ca1\u6709\u7ec8\u6b62\n            if (!completedAbruptly) {\n                int min = allowCoreThreadTimeOut ? 0 : corePoolSize;\n                if (min == 0 &amp;&amp; ! workQueue.isEmpty())\n                    min = 1;\n                if (workerCountOf(c) &gt;= min)\n                    return; \/\/ replacement not needed\n            }\n            addWorker(null, false);     \/\/\u5f02\u5e38\u7ec8\u6b62\u7ebf\u7a0b\u7684\u8bdd\uff0c\u9700\u8981\u5728\u5e38\u89c1\u4e00\u4e2a\u7ebf\u7a0b\n        }\n    }\n<\/code><\/pre>\n<p>\u5c0f\u7ed3\uff1aprocessWorkerExit()\u65b9\u6cd5\u4e3b\u8981\u529f\u80fd\uff1b<\/p>\n<ol>\n<li>\u771f\u5b9e\u5b8c\u6210\u7ebf\u7a0b\u6c60\u7ebf\u7a0b\u7684\u56de\u6536\uff1b<\/li>\n<li>\u8c03\u7528\u5c1d\u8bd5\u7ec8\u6b62\u7ebf\u7a0b\u6c60\uff1b<\/li>\n<li>\u4fdd\u8bc1\u7ebf\u7a0b\u6c60\u6b63\u5e38\u8fd0\u884c\uff1b<\/li>\n<\/ol>\n<p>2.1.3.7\u3001\u5c1d\u8bd5\u7ec8\u6b62\u7ebf\u7a0b\u6c60<\/p>\n<pre><code>    final void tryTerminate() {\n        for (;;) {\n            int c = ctl.get();\n            \n            \/\/\u82e5\u7ebf\u7a0b\u6c60\u6b63\u5728\u6267\u884c\u3001\u7ebf\u7a0b\u6c60\u5df2\u7ec8\u6b62\u3001\u7ebf\u7a0b\u6c60\u8fd8\u9700\u8981\u6267\u884c\u7f13\u5b58\u961f\u5217\u4e2d\u7684\u4efb\u52a1\u65f6\uff0c\u8fd4\u56de\n            if (isRunning(c) ||\n                runStateAtLeast(c, TIDYING) ||\n                (runStateOf(c) == SHUTDOWN &amp;&amp; ! workQueue.isEmpty()))\n                return;\n                \n            \/\/\u6267\u884c\u5230\u8fd9\u91cc\uff0c\u7ebf\u7a0b\u6c60\u4e3aSHUTDOWN\u4e14\u65e0\u5f85\u6267\u884c\u4efb\u52a1 \u6216 STOP \u72b6\u6001\n            if (workerCountOf(c) != 0) {\n                interruptIdleWorkers(ONLY_ONE);     \/\/\u53ea\u4e2d\u65ad\u4e00\u4e2a\u7ebf\u7a0b\n                return;\n            }\n\u200b\n            \/\/\u6267\u884c\u5230\u8fd9\u91cc\uff0c\u7ebf\u7a0b\u6c60\u5df2\u7ecf\u6ca1\u6709\u53ef\u7528\u7ebf\u7a0b\u4e86\uff0c\u53ef\u4ee5\u7ec8\u6b62\u4e86\n            final ReentrantLock mainLock = this.mainLock;\n            mainLock.lock();\n            try {\n                if (ctl.compareAndSet(c, ctlOf(TIDYING, 0))) {  \/\/CAS\u8bbe\u7f6e\u7ebf\u7a0b\u6c60\u7ec8\u6b62\n                    try {\n                        terminated();   \/\/\u6267\u884c\u94a9\u5b50\u65b9\u6cd5\n                    } finally {\n                        ctl.set(ctlOf(TERMINATED, 0));  \/\/\u8fd9\u91cc\u5c06\u7ebf\u7a0b\u6c60\u8bbe\u4e3a\u7ec8\u6001\n                        termination.signalAll();\n                    }\n                    return;\n                }\n            } finally {\n                mainLock.unlock();\n            }\n            \/\/ else retry on failed CAS\n        }\n    }\n<\/code><\/pre>\n<p>\u5c0f\u7ed3\uff1atryTerminate()\u65b9\u6cd5\u4e3b\u8981\u529f\u80fd\uff1b<\/p>\n<ol>\n<li>\u5b9e\u9645\u5c1d\u8bd5\u7ec8\u6b62\u7ebf\u7a0b\u6c60\uff1b<\/li>\n<li>\u7ec8\u6b62\u6210\u529f\u5219\u8c03\u7528\u94a9\u5b50\u65b9\u6cd5\uff0c\u5e76\u4e14\u5c06\u7ebf\u7a0b\u6c60\u7f6e\u4e3a\u7ec8\u6001\u3002<\/li>\n<\/ol>\n<h4>2.2\u3001JAVA\u7ebf\u7a0b\u6c60\u603b\u7ed3<\/h4>\n<p>\u4ee5\u4e0a\u901a\u8fc7\u5bf9JAVA\u7ebf\u7a0b\u6c60\u7684\u5177\u4f53\u5206\u6790\u6211\u4eec\u53ef\u4ee5\u770b\u51fa\uff0c\u867d\u7136\u6d41\u7a0b\u770b\u4f3c\u590d\u6742\uff0c\u4f46\u5176\u5b9e\u6709\u5f88\u591a\u5185\u5bb9\u90fd\u662f\u72b6\u6001\u91cd\u590d\u6821\u9a8c\u3001\u7ebf\u7a0b\u5b89\u5168\u7684\u4fdd\u8bc1\u7b49\u5185\u5bb9\uff0c\u5176\u4e3b\u8981\u7684\u529f\u80fd\u4e0e\u6211\u4eec\u524d\u9762\u6240\u63d0\u51fa\u7684\u8bbe\u8ba1\u529f\u80fd\u4e00\u81f4\uff0c\u53ea\u662f\u989d\u5916\u589e\u52a0\u4e86\u4e00\u4e9b\u6269\u5c55\uff0c\u4e0b\u9762\u6211\u4eec\u7b80\u5355\u6574\u7406\u4e0b\u7ebf\u7a0b\u6c60\u7684\u529f\u80fd\uff1b<\/p>\n<p>2.2.1\u3001\u4e3b\u8981\u529f\u80fd<\/p>\n<ol>\n<li>\u7ebf\u7a0b\u6570\u91cf\u53ca\u5b58\u6d3b\u65f6\u95f4\u7684\u7ba1\u7406\uff1b<\/li>\n<li>\u5f85\u5904\u7406\u4efb\u52a1\u7684\u5b58\u50a8\u529f\u80fd\uff1b<\/li>\n<li>\u7ebf\u7a0b\u590d\u7528\u673a\u5236\u529f\u80fd\uff1b<\/li>\n<li>\u4efb\u52a1\u8d85\u91cf\u7684\u62d2\u7edd\u529f\u80fd\uff1b<\/li>\n<\/ol>\n<p>2.2.2\u3001\u6269\u5c55\u529f\u80fd<\/p>\n<ol>\n<li>\u7b80\u5355\u7684\u6267\u884c\u7ed3\u679c\u7edf\u8ba1\u529f\u80fd\uff1b<\/li>\n<li>\u63d0\u4f9b\u7ebf\u7a0b\u6267\u884c\u5f02\u5e38\u5904\u7406\u673a\u5236\uff1b<\/li>\n<li>\u6267\u884c\u524d\u540e\u5904\u7406\u6d41\u7a0b\u81ea\u5b9a\u4e49\uff1b<\/li>\n<li>\u63d0\u4f9b\u7ebf\u7a0b\u521b\u5efa\u65b9\u5f0f\u7684\u81ea\u5b9a\u4e49\uff1b<\/li>\n<\/ol>\n<p>2.2.3\u3001\u6d41\u7a0b\u603b\u7ed3<\/p>\n<p>\u4ee5\u4e0a\u901a\u8fc7\u5bf9JAVA\u7ebf\u7a0b\u6c60\u4efb\u52a1\u63d0\u4ea4\u6d41\u7a0b\u7684\u5206\u6790\u6211\u4eec\u53ef\u4ee5\u770b\u51fa\uff0c\u7ebf\u7a0b\u6c60\u6267\u884c\u7684\u7b80\u5355\u6d41\u7a0b\u5982\u4e0b\u56fe\u6240\u793a\uff1b<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/s3.cn-north-1.jdcloud-oss.com\/shendengbucket1\/2022-11-21-18-06DlWGyY11FjcoyluS.png\" alt=\"\" title=\"\"><\/p>\n<h4>2.3\u3001JAVA\u7ebf\u7a0b\u6c60\u4f7f\u7528<\/h4>\n<p>\u7ebf\u7a0b\u6c60\u57fa\u672c\u4f7f\u7528\u9a8c\u8bc1\u4e0a\u8ff0\u6d41\u7a0b\uff1a<\/p>\n<pre><code>   public static void main(String[] args) throws Exception {\n        \n        \/\/\u521b\u5efa\u7ebf\u7a0b\u6c60\n       ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(\n               5, 10, 100, TimeUnit.SECONDS, new ArrayBlockingQueue(5));\n        \n        \/\/\u52a0\u51654\u4e2a\u4efb\u52a1\uff0c\u5c0f\u4e8e\u6838\u5fc3\u7ebf\u7a0b\uff0c\u5e94\u8be5\u53ea\u67094\u4e2a\u6838\u5fc3\u7ebf\u7a0b\uff0c\u961f\u5217\u4e3a0\n        for (int i = 0; i &lt; 4; i++) {\n            threadPoolExecutor.submit(new MyRunnable());\n        }\n        System.out.println(&quot;worker count = &quot; + threadPoolExecutor.getPoolSize());   \/\/worker count = 4\n        System.out.println(&quot;queue size = &quot; + threadPoolExecutor.getQueue().size()); \/\/queue size = 0\n        \n        \/\/\u518d\u52a04\u4e2a\u4efb\u52a1\uff0c\u8d85\u8fc7\u6838\u5fc3\u7ebf\u7a0b\uff0c\u4f46\u662f\u6ca1\u6709\u8d85\u8fc7\u6838\u5fc3\u7ebf\u7a0b + \u7f13\u5b58\u961f\u5217\u5bb9\u91cf\uff0c\u5e94\u8be55\u4e2a\u6838\u5fc3\u7ebf\u7a0b\uff0c\u961f\u5217\u4e3a3\n        for (int i = 0; i &lt; 4; i++) {\n            threadPoolExecutor.submit(new MyRunnable());\n        }\n        System.out.println(&quot;worker count = &quot; + threadPoolExecutor.getPoolSize());   \/\/worker count = 5\n        System.out.println(&quot;queue size = &quot; + threadPoolExecutor.getQueue().size()); \/\/queue size = 3\n        \n        \/\/\u518d\u52a04\u4e2a\u4efb\u52a1\uff0c\u961f\u5217\u6ee1\u4e86\uff0c\u5e94\u8be55\u4e2a\u70ed\u6838\u5fc3\u7ebf\u7a0b\uff0c\u961f\u52175\u4e2a\uff0c\u975e\u6838\u5fc3\u7ebf\u7a0b2\u4e2a\n        for (int i = 0; i &lt; 4; i++) {\n            threadPoolExecutor.submit(new MyRunnable());\n        }\n        System.out.println(&quot;worker count = &quot; + threadPoolExecutor.getPoolSize());   \/\/worker count = 7\n        System.out.println(&quot;queue size = &quot; + threadPoolExecutor.getQueue().size()); \/\/queue size = 5\n        \n        \/\/\u518d\u52a04\u4e2a\u4efb\u52a1\uff0c\u6838\u5fc3\u7ebf\u7a0b\u6ee1\u4e86\uff0c\u5e94\u8be55\u4e2a\u70ed\u6838\u5fc3\u7ebf\u7a0b\uff0c\u961f\u52175\u4e2a\uff0c\u975e\u6838\u5fc3\u7ebf\u7a0b5\u4e2a\uff0c\u6700\u540e\u4e00\u4e2a\u62d2\u7edd\n        for (int i = 0; i &lt; 4; i++) {\n            try {\n                threadPoolExecutor.submit(new MyRunnable());\n            } catch (Exception e) {\n                e.printStackTrace();    \/\/java.util.concurrent.RejectedExecutionException\n            }\n        }\n        System.out.println(&quot;worker count = &quot; + threadPoolExecutor.getPoolSize());   \/\/worker count = 10\n        System.out.println(&quot;queue size = &quot; + threadPoolExecutor.getQueue().size()); \/\/queue size = 5\n        System.out.println(threadPoolExecutor.getTaskCount());  \/\/\u5171\u6267\u884c15\u4e2a\u4efb\u52a1\n        \n        \/\/\u6267\u884c\u5b8c\u6210\uff0c\u4f11\u772015\u79d2\uff0c\u975e\u6838\u5fc3\u7ebf\u7a0b\u91ca\u653e\uff0c\u5e94\u8be55\u4e2a\u6838\u5fc3\u7ebf\u7a0b\uff0c\u961f\u5217\u4e3a0\n        Thread.sleep(1500);\n        System.out.println(&quot;worker count = &quot; + threadPoolExecutor.getPoolSize());   \/\/worker count = 5\n        System.out.println(&quot;queue size = &quot; + threadPoolExecutor.getQueue().size()); \/\/queue size = 0\n        \n        \/\/\u5173\u95ed\u7ebf\u7a0b\u6c60\n        threadPoolExecutor.shutdown();\n    }\n<\/code><\/pre>\n<blockquote>\n<p>\u4f5c\u8005\uff1a\u4eac\u4e1c\u96f6\u552e \u79e6\u6d69\u7136<\/p>\n<p>\u6765\u6e90\uff1a\u4eac\u4e1c\u4e91\u5f00\u53d1\u8005\u793e\u533a \u8f6c\u8f7d\u8bf7\u6ce8\u660e\u6765\u6e90<\/p>\n<\/blockquote>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000044248126\">https:\/\/segmentfault.com\/a\/1190000044248126<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u7ebf\u7a0b 1\u3001\u4ec0\u4e48\u662f\u7ebf\u7a0b \u7ebf\u7a0b(thread)\u662f\u64cd\u4f5c\u7cfb\u7edf\u80fd\u591f\u8fdb\u884c\u8fd0\u7b97\u8c03\u5ea6\u7684\u6700\u5c0f\u5355\u4f4d\u3002\u5b83\u88ab\u5305\u542b\u5728\u8fdb\u7a0b\u4e4b\u4e2d\uff0c\u662f\u8fdb\u7a0b [&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-10008315","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\/10008315","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=10008315"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008315\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10008315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10008315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10008315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}