{"id":8363,"date":"2024-06-12T08:01:01","date_gmt":"2024-06-12T00:01:01","guid":{"rendered":""},"modified":"2024-06-12T08:01:01","modified_gmt":"2024-06-12T00:01:01","slug":"java\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u5426\u7ed3\u675f\u53e6\u4e00\u4e2a\u6c38\u4e0d\u505c\u6b62\u7684\u7ebf\u7a0b\u6267\u884c_\u5982\u4f55\u7ec8\u6b62\u4e00\u4e2a\u7ebf\u7a0b","status":"publish","type":"post","link":"https:\/\/mushiming.com\/8363.html","title":{"rendered":"java\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u5426\u7ed3\u675f\u53e6\u4e00\u4e2a\u6c38\u4e0d\u505c\u6b62\u7684\u7ebf\u7a0b\u6267\u884c_\u5982\u4f55\u7ec8\u6b62\u4e00\u4e2a\u7ebf\u7a0b"},"content":{"rendered":"<p>\u5728Java\u4e2d\u505c\u6b62\u4e00\u4e2a\u7ebf\u7a0b\u6709\u4e09\u79cd\u529e\u6cd5&nbsp;\uff1a<\/p>\n<p>1.\u6b63\u5e38\u7ed3\u675f\u6267\u884c\uff1b<\/p>\n<p>2.\u53d1\u751f\u5f02\u5e38;<\/p>\n<p>3.\u88ab\u5176\u4ed6\u7ebf\u7a0bstop(Java\u5b98\u65b9\u4e0d\u5efa\u8bae)<\/p>\n<p>\u53c2\u8003\uff1ahttps:\/\/docs.oracle.com\/javase\/8\/docs\/technotes\/guides\/concurrency\/threadPrimitiveDeprecation.html<\/p>\n<h4 style=\"margin-left:0px;\"><span style=\"color:#000000;\">\u4e3a\u4ec0\u4e48<code>Thread.stop<\/code>\u5f03\u7528\uff1f<\/span><\/h4>\n<p><span style=\"color:#000000;\">\u56e0\u4e3a\u5b83\u672c\u8d28\u4e0a\u662f\u4e0d\u5b89\u5168\u7684\u3002\u505c\u6b62\u7ebf\u7a0b\u4f1a\u5bfc\u81f4\u5b83\u89e3\u9501\u5df2\u9501\u5b9a\u7684\u6240\u6709\u76d1\u89c6\u5668\u3002\uff08\u5f53<code>ThreadDeath<\/code>\u5f02\u5e38\u4f20\u64ad\u5230\u5806\u6808\u4e2d\u65f6\uff0c\u76d1\u89c6\u5668\u5c06\u88ab\u89e3\u9501\u3002\uff09\u5982\u679c\u5148\u524d\u53d7\u8fd9\u4e9b\u76d1\u89c6\u5668\u4fdd\u62a4\u7684\u4efb\u4f55\u5bf9\u8c61\u5904\u4e8e\u4e0d\u4e00\u81f4\u72b6\u6001\uff0c\u5219\u5176\u4ed6\u7ebf\u7a0b\u73b0\u5728\u53ef\u4ee5\u4ee5\u4e0d\u4e00\u81f4\u7684\u72b6\u6001\u67e5\u770b\u8fd9\u4e9b\u5bf9\u8c61\u3002\u636e\u8bf4\u8fd9\u4e9b\u7269\u4f53\u5df2\u88ab&nbsp;<em>\u635f\u574f<\/em>\u3002\u5f53\u7ebf\u7a0b\u5bf9\u53d7\u635f\u5bf9\u8c61\u8fdb\u884c\u64cd\u4f5c\u65f6\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u4efb\u610f\u884c\u4e3a\u3002\u8fd9\u79cd\u884c\u4e3a\u53ef\u80fd\u5f88\u5fae\u5999\u5e76\u4e14\u96be\u4ee5\u68c0\u6d4b\uff0c\u6216\u8005\u53ef\u80fd\u662f\u660e\u663e\u7684\u3002\u4e0e\u5176\u4ed6\u672a\u7ecf\u68c0\u67e5\u7684\u5f02\u5e38\u4e0d\u540c\uff0c\u5b83\u4f1a&nbsp;<code>ThreadDeath<\/code>\u9ed8\u9ed8\u5730\u6740\u6b7b\u7ebf\u7a0b;&nbsp;\u56e0\u6b64\uff0c\u7528\u6237\u6ca1\u6709\u8b66\u544a\u4ed6\u7684\u7a0b\u5e8f\u53ef\u80fd\u88ab\u7834\u574f\u3002<\/span><\/p>\n<p><span style=\"color:#000000;\"><img decoding=\"async\" src=\"https:\/\/img.mushiming.top\/app\/mushiming_com\/00574863422e4b0c9eab4f349fb7aa50.png\" =\"\" =\"\" alt=\"java\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u5426\u7ed3\u675f\u53e6\u4e00\u4e2a\u6c38\u4e0d\u505c\u6b62\u7684\u7ebf\u7a0b\u6267\u884c_\u5982\u4f55\u7ec8\u6b62\u4e00\u4e2a\u7ebf\u7a0b (https:\/\/mushiming.com\/)  \u7b2c1\u5f20\" title=\"java\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u5426\u7ed3\u675f\u53e6\u4e00\u4e2a\u6c38\u4e0d\u505c\u6b62\u7684\u7ebf\u7a0b\u6267\u884c_\u5982\u4f55\u7ec8\u6b62\u4e00\u4e2a\u7ebf\u7a0b  \u7b2c1\u5f20-\u7a46\u4e16\u660e\u535a\u5ba2\" ><\/span><\/p>\n<p>&nbsp;<\/p>\n<p>\u6240\u4ee5\u5982\u679c\u9047\u5230\u4e00\u79cd\u7279\u6b8a\u60c5\u51b5\u67d0\u4e00\u4e2a\u7ebf\u7a0bA\u4f1a\u4e00\u76f4\u6267\u884c\u4e0b\u53bb\u505c\u4e0d\u4e0b\u6765\uff0c\u8fd9\u79cd\u60c5\u51b5\u662f\u5b58\u5728\u7684\u6bd4\u5982\u90a3\u79cd\u9700\u8981\u6301\u7eed\u53d6\u6837\u7684\u7ebf\u7a0bA\uff0c\u5f53\u7136\u4e86\u5728\u6b63\u5e38\u4ee3\u7801\u91cc\u4f1a\u6709\u201c\u505c\u6b62\u201d\u529f\u80fd\uff0c\u5916\u90e8\u7ebf\u7a0bB\u53ef\u4ee5\u53d1\u9001\u505c\u6b62\u4fe1\u53f7\u7ed9A\uff0cA\u53ef\u4ee5\u76f4\u63a5\u7ed3\u675f\u3002<\/p>\n<p>\u5982\u679cA\u7ebf\u7a0b\u6ca1\u6709\u8fd9\u79cd\u4fe1\u53f7\u91cf\u90a3\u4e48B\u7ebf\u7a0b\u8fd8\u53ef\u4ee5\u4e3b\u52a8\u505c\u6b62\u4ed6\u4e48\uff1f\u7b54\u6848\u662f\u4e0d\u53ef\u4ee5\uff01<\/p>\n<pre class=\"has\"><code class=\"language-java\">public class Test { public static void main(String args[]) throws InterruptedException { Thread thread1 = new Thread() { public void run() { fun_a(); } }; thread1.start(); int a = 0; while (a &lt; 100) { Thread.sleep(1000); a++; if (a == 3) { a = 100; thread1.interrupt(); \/\/thread1.stop(); \/\/throw new RuntimeException(\"\u4e3b\u51fd\u6570\u629b\u51fa\u5f02\u5e38\"); } } } public static void fun_a() { for (; ; ) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(\"&gt;&gt; \" + DateUtil.getNowTimeString()); } } } <\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/img.mushiming.top\/app\/mushiming_com\/b062c86c89494d449a648794a845a57e.png\" =\"\" =\"\" alt=\"java\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u5426\u7ed3\u675f\u53e6\u4e00\u4e2a\u6c38\u4e0d\u505c\u6b62\u7684\u7ebf\u7a0b\u6267\u884c_\u5982\u4f55\u7ec8\u6b62\u4e00\u4e2a\u7ebf\u7a0b (https:\/\/mushiming.com\/)  \u7b2c2\u5f20\" title=\"java\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u5426\u7ed3\u675f\u53e6\u4e00\u4e2a\u6c38\u4e0d\u505c\u6b62\u7684\u7ebf\u7a0b\u6267\u884c_\u5982\u4f55\u7ec8\u6b62\u4e00\u4e2a\u7ebf\u7a0b  \u7b2c2\u5f20-\u7a46\u4e16\u660e\u535a\u5ba2\" ><\/p>\n<p>&nbsp;\u53ef\u4ee5\u770b\u5230interrupt\u5e76\u4e0d\u80fd\u8ba9\u8fd0\u884c\u4e2d\u7684\u7ebf\u7a0b\u505c\u6b62\uff0c\u8fd9\u4e2a\u662f\u5f88\u5bb9\u6613\u88ab\u8bef\u89e3\u7684\u5730\u65b9\u3002\u8fd9\u4e2a\u65b9\u6cd5\u7684\u4f5c\u7528\u5e76\u4e0d\u662f\u4e2d\u65ad\u7ebf\u7a0b\uff0c\u800c\u662f\u8bbe\u7f6e\u4e00\u4e2a\u6807\u8bc6\uff0c\u901a\u77e5\u8be5\u7ebf\u7a0b\u53ef\u4ee5\u88ab\u4e2d\u65ad\u4e86\uff0c\u5230\u5e95\u662f\u7ee7\u7eed\u6267\u884c\uff0c\u8fd8\u662f\u4e2d\u65ad\u8fd4\u56de\uff0c\u7531\u7ebf\u7a0b\u672c\u8eab\u81ea\u5df1\u51b3\u5b9a\u3002<\/p>\n<p>\u5f53\u5bf9\u4e00\u4e2a\u7ebf\u7a0b\u8c03\u7528\u4e86<code>interrupt()<\/code>\u4e4b\u540e\uff0c\u5982\u679c\u8be5\u7ebf\u7a0b\u5904\u4e8e\u88ab\u963b\u585e\u72b6\u6001\uff08\u6bd4\u5982\u6267\u884c\u4e86wait\u3001sleep\u6216join\u7b49\u65b9\u6cd5\uff09\uff0c\u90a3\u4e48\u4f1a\u7acb\u5373\u9000\u51fa\u963b\u585e\u72b6\u6001\uff0c\u5e76\u629b\u51fa\u4e00\u4e2a<code>InterruptedException<\/code>\u5f02\u5e38\uff0c\u5728\u4ee3\u7801\u4e2dcatch\u8fd9\u4e2a\u5f02\u5e38\u8fdb\u884c\u540e\u7eed\u5904\u7406\u3002\u5982\u679c\u7ebf\u7a0b\u4e00\u76f4\u5904\u4e8e\u8fd0\u884c\u72b6\u6001\uff0c\u90a3\u4e48\u53ea\u4f1a\u628a\u8be5\u7ebf\u7a0b\u7684\u4e2d\u65ad\u6807\u5fd7\u8bbe\u7f6e\u4e3a true\uff0c\u4ec5\u6b64\u800c\u5df2\uff0c\u6240\u4ee5<code>interrupt()<\/code>\u5e76\u4e0d\u80fd\u771f\u6b63\u7684\u4e2d\u65ad\u7ebf\u7a0b\uff0c\u4e0d\u8fc7\u5728rpc\u8c03\u7528\u7684\u573a\u666f\u4e2d\uff0c\u8bf7\u6c42\u7ebf\u7a0b\u4e00\u822c\u90fd\u5904\u4e8e\u963b\u585e\u72b6\u6001\uff0c\u7b49\u5f85\u6570\u636e\u8fd4\u56de\uff0c\u8fd9\u65f6<code>interrupt()<\/code>\u65b9\u6cd5\u662f\u53ef\u4ee5\u6d3e\u4e0a\u7528\u573a\u7684\u3002<\/p>\n<p>\u53c2\u8003\uff1aJava\u4e2d\u5982\u4f55\u5b9e\u73b0\u7ebf\u7a0b\u7684\u8d85\u65f6\u4e2d\u65ad<\/p>\n<p>&nbsp;<\/p>\n<p>\u4fee\u6539\u5b50\u7ebf\u7a0b\u7684\u4ee3\u7801\uff1a<\/p>\n<pre class=\"has\"><code class=\"language-java\">public static void fun_a() { for (; ; ) { try { Thread.sleep(1000); } catch (InterruptedException e) { throw new RuntimeException(\"\u5b50\u7ebf\u7a0b\u629b\u51fa\u5f02\u5e38\"); \/\/e.printStackTrace(); } System.out.println(\"&gt;&gt; \" + DateUtil.getNowTimeString()); } }<\/code><\/pre>\n<p>\u8fd9\u6b21\u662f\u53ef\u4ee5\u7ed3\u675f\u5b50\u7ebf\u7a0b\uff0c\u524d\u63d0\u662f\u5b50\u7ebf\u7a0b\u81ea\u5df1\u6709\u5f02\u5e38\u6355\u83b7\u673a\u5236\uff0c\u53ef\u4ee5\u63a5\u53d7\u5176\u4ed6\u7ebf\u7a0b\u53d1\u6765\u7684<code>InterruptedException\uff1a<\/code><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.mushiming.top\/app\/mushiming_com\/93f909b61f11421aabd1d2b983f4c0a2.png\" =\"\" =\"\" alt=\"java\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u5426\u7ed3\u675f\u53e6\u4e00\u4e2a\u6c38\u4e0d\u505c\u6b62\u7684\u7ebf\u7a0b\u6267\u884c_\u5982\u4f55\u7ec8\u6b62\u4e00\u4e2a\u7ebf\u7a0b (https:\/\/mushiming.com\/)  \u7b2c3\u5f20\" title=\"java\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u5426\u7ed3\u675f\u53e6\u4e00\u4e2a\u6c38\u4e0d\u505c\u6b62\u7684\u7ebf\u7a0b\u6267\u884c_\u5982\u4f55\u7ec8\u6b62\u4e00\u4e2a\u7ebf\u7a0b  \u7b2c3\u5f20-\u7a46\u4e16\u660e\u535a\u5ba2\" ><\/p>\n<p>&nbsp;<\/p>\n<p>\u4e3b\u7ebf\u7a0b\u6bcf\u96942\u79d2\u5bf9\u5b50\u7ebf\u7a0b\u8fdb\u884c\u4e00\u6b21Interrupted\uff1a<\/p>\n<pre class=\"has\"><code class=\"language-java\">package com.t.www; public class Test { final static Object lock = new Object(); volatile boolean stop = false; public static void main(String args[]) throws InterruptedException { Thread thread1 = new Thread() { public void run() { fun_a(); } }; thread1.start(); System.out.println(\"&gt; 1 \u4e3b\u7ebf\u7a0bstart \" + DateUtil.getNowTimeString()); int a = 0; while (a &lt; 3) { Thread.sleep(2000); a++; System.out.println(\"&gt; 2 \u4e3b\u7ebf\u7a0b\u5bf9\u5b50\u7ebf\u7a0b\u5f00\u59cbinterrupt \" + DateUtil.getNowTimeString()); thread1.interrupt(); System.out.println(\"&gt; 3 \u4e3b\u7ebf\u7a0b\u5bf9\u5b50\u7ebf\u7a0b\u5b8c\u6210interrupt \" + DateUtil.getNowTimeString()); } } public static void fun_a() { for (; ; ) { try { System.out.println(\"&gt;&gt; 1 \u5b50\u7ebf\u7a0bwait \" + DateUtil.getNowTimeString()); synchronized (lock) { lock.wait(); } Thread.sleep(1000); } catch (InterruptedException e) { \/\/throw new RuntimeException(\"\u5b50\u7ebf\u7a0b\u629b\u51fa\u5f02\u5e38\"); e.printStackTrace(); } System.out.println(\"&gt;&gt; 2 \u5b50\u7ebf\u7a0b\u5b8c\u6210 \" + DateUtil.getNowTimeString()); } } } <\/code><\/pre>\n<p>&nbsp;<img decoding=\"async\" src=\"https:\/\/img.mushiming.top\/app\/mushiming_com\/fb0ce6b22dab44bebb7edfd7d3c63098.png\" =\"\" =\"\" alt=\"java\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u5426\u7ed3\u675f\u53e6\u4e00\u4e2a\u6c38\u4e0d\u505c\u6b62\u7684\u7ebf\u7a0b\u6267\u884c_\u5982\u4f55\u7ec8\u6b62\u4e00\u4e2a\u7ebf\u7a0b (https:\/\/mushiming.com\/)  \u7b2c4\u5f20\" title=\"java\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u5426\u7ed3\u675f\u53e6\u4e00\u4e2a\u6c38\u4e0d\u505c\u6b62\u7684\u7ebf\u7a0b\u6267\u884c_\u5982\u4f55\u7ec8\u6b62\u4e00\u4e2a\u7ebf\u7a0b  \u7b2c4\u5f20-\u7a46\u4e16\u660e\u535a\u5ba2\" ><\/p>\n<p>&nbsp;\u4fee\u6539\u5b50\u7ebf\u7a0b\u4ee3\u7801\uff1a<\/p>\n<pre class=\"has\"><code class=\"language-java\">try { System.out.println(\"&gt;&gt; 1 \u5b50\u7ebf\u7a0bwait \" + DateUtil.getNowTimeString()); synchronized (lock) { lock.wait(); } Thread.sleep(1000); } catch (InterruptedException e) { \/\/throw new RuntimeException(\"\u5b50\u7ebf\u7a0b\u629b\u51fa\u5f02\u5e38\"); \/\/e.printStackTrace(); System.out.println(\"&gt;&gt; 2 \u5b50\u7ebf\u7a0b\u6355\u83b7\u5f02\u5e38 \" + DateUtil.getNowTimeString()); }<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/img.mushiming.top\/app\/mushiming_com\/9db4d0c8ba3543168e71c99cc1e81a6d.png\" =\"\" =\"\" alt=\"java\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u5426\u7ed3\u675f\u53e6\u4e00\u4e2a\u6c38\u4e0d\u505c\u6b62\u7684\u7ebf\u7a0b\u6267\u884c_\u5982\u4f55\u7ec8\u6b62\u4e00\u4e2a\u7ebf\u7a0b (https:\/\/mushiming.com\/)  \u7b2c5\u5f20\" title=\"java\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u5426\u7ed3\u675f\u53e6\u4e00\u4e2a\u6c38\u4e0d\u505c\u6b62\u7684\u7ebf\u7a0b\u6267\u884c_\u5982\u4f55\u7ec8\u6b62\u4e00\u4e2a\u7ebf\u7a0b  \u7b2c5\u5f20-\u7a46\u4e16\u660e\u535a\u5ba2\" ><\/p>\n<p>\u4ece\u8fd0\u884c\u7ed3\u679c\u770b\u548c\u524d\u9762\u4e00\u81f4\uff0c\u53ea\u662f\u6ca1\u6709\u629b\u51fa\u5f02\u5e38\u3002&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\u4fee\u6539\u4ee3\u7801\u5b50\u7ebf\u7a0b\u4f7f\u7528while(!Thread.currentThread().isInterrupted())\u5224\u65ad\uff1a<\/p>\n<pre class=\"has\"><code class=\"language-java\">public class Test { public static void main(String args[]) throws InterruptedException { Thread thread1 = new Thread() { public void run() { fun_a(); } }; thread1.start(); System.out.println(\"&gt; 1 \u4e3b\u7ebf\u7a0bstart \" + DateUtil.getNowTimeString()); int a = 0; while (a &lt; 3) { Thread.sleep(2000); a++; System.out.println(\"&gt; 2 \u4e3b\u7ebf\u7a0b\u5bf9\u5b50\u7ebf\u7a0b\u5f00\u59cbinterrupt \" + DateUtil.getNowTimeString()); thread1.interrupt(); System.out.println(\"&gt; 3 \u4e3b\u7ebf\u7a0b\u5bf9\u5b50\u7ebf\u7a0b\u5b8c\u6210interrupt \" + DateUtil.getNowTimeString()); } } public static void fun_a() { while(!Thread.currentThread().isInterrupted()){ try { System.out.println(\"&gt;&gt; 1 \u5b50\u7ebf\u7a0b \" + DateUtil.getNowTimeString()); Thread.sleep(1000); } catch (InterruptedException e) { \/\/throw new RuntimeException(\"\u5b50\u7ebf\u7a0b\u629b\u51fa\u5f02\u5e38\"); \/\/e.printStackTrace(); System.out.println(\"&gt;&gt; 2 \u5b50\u7ebf\u7a0b\u6355\u83b7\u5f02\u5e38 \" + DateUtil.getNowTimeString()); } System.out.println(\"&gt;&gt; 3 \u5b50\u7ebf\u7a0b\u5b8c\u6210 \" + DateUtil.getNowTimeString()); } System.out.println(\"&gt;&gt; 4 \u5b50\u7ebf\u7a0b\u6b63\u5e38\u7ed3\u675f \" + DateUtil.getNowTimeString()); } } <\/code><\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\u8fd9\u6b21\u56e0\u4e3a\u5b50\u7ebf\u7a0b\u589e\u52a0\u4e86\u72b6\u6001\u5224\u65ad\u6240\u4ee5\u53ef\u4ee5\u6b63\u5e38\u7ed3\u675f\uff1a&nbsp;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.mushiming.top\/app\/mushiming_com\/3a74a954f1364cd2a5348258485b931a.png\" =\"\" =\"\" alt=\"java\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u5426\u7ed3\u675f\u53e6\u4e00\u4e2a\u6c38\u4e0d\u505c\u6b62\u7684\u7ebf\u7a0b\u6267\u884c_\u5982\u4f55\u7ec8\u6b62\u4e00\u4e2a\u7ebf\u7a0b (https:\/\/mushiming.com\/)  \u7b2c6\u5f20\" title=\"java\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u5426\u7ed3\u675f\u53e6\u4e00\u4e2a\u6c38\u4e0d\u505c\u6b62\u7684\u7ebf\u7a0b\u6267\u884c_\u5982\u4f55\u7ec8\u6b62\u4e00\u4e2a\u7ebf\u7a0b  \u7b2c6\u5f20-\u7a46\u4e16\u660e\u535a\u5ba2\" ><\/p>\n<p>\u6bd4\u8f83\u4f18\u96c5\u7684\u65b9\u5f0f\u662f\u4f7f\u7528\u4e00\u4e2a\u53d8\u91cf\u5728\u7ebf\u7a0b\u95f4\u901a\u4fe1\uff0c\u9700\u8981\u6ce8\u610f\u7684\u662f\u8981\u4fdd\u8bc1\u53ef\u89c1\u6027\uff1a<\/p>\n<pre class=\"has\"><code class=\"language-java\">public class Test { private static volatile boolean finished = false; \/\/ \u2460 volatile\u6761\u4ef6\u53d8\u91cf public static void main(String args[]) throws InterruptedException { Thread thread1 = new Thread() { public void run() { fun_a(); } }; thread1.start(); System.out.println(\"&gt; 1 \u4e3b\u7ebf\u7a0bstart \" + DateUtil.getNowTimeString()); int a = 0; while (a &lt; 3) { Thread.sleep(2000); a++; } System.out.println(\"&gt; 1 \u4e3b\u7ebf\u7a0b a=\" +a+\" \"+ DateUtil.getNowTimeString()); finished=true; } public static void fun_a() { while(!finished){ try { System.out.println(\"&gt;&gt; 1 \u5b50\u7ebf\u7a0b \" + DateUtil.getNowTimeString()); Thread.sleep(1000); } catch (InterruptedException e) { \/\/throw new RuntimeException(\"\u5b50\u7ebf\u7a0b\u629b\u51fa\u5f02\u5e38\"); \/\/e.printStackTrace(); System.out.println(\"&gt;&gt; 2 \u5b50\u7ebf\u7a0b\u6355\u83b7\u5f02\u5e38 \" + DateUtil.getNowTimeString()); } System.out.println(\"&gt;&gt; 3 \u5b50\u7ebf\u7a0b\u5b8c\u6210 \" + DateUtil.getNowTimeString()); } System.out.println(\"&gt;&gt; 4 \u5b50\u7ebf\u7a0b\u6b63\u5e38\u7ed3\u675f \" + DateUtil.getNowTimeString()); } } <\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/img.mushiming.top\/app\/mushiming_com\/85b0b12778824e7785eb670b9ad714a6.png\" =\"\" =\"\" alt=\"java\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u5426\u7ed3\u675f\u53e6\u4e00\u4e2a\u6c38\u4e0d\u505c\u6b62\u7684\u7ebf\u7a0b\u6267\u884c_\u5982\u4f55\u7ec8\u6b62\u4e00\u4e2a\u7ebf\u7a0b (https:\/\/mushiming.com\/)  \u7b2c7\u5f20\" title=\"java\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u5426\u7ed3\u675f\u53e6\u4e00\u4e2a\u6c38\u4e0d\u505c\u6b62\u7684\u7ebf\u7a0b\u6267\u884c_\u5982\u4f55\u7ec8\u6b62\u4e00\u4e2a\u7ebf\u7a0b  \u7b2c7\u5f20-\u7a46\u4e16\u660e\u535a\u5ba2\" ><\/p>\n<p>------------------<\/p>\n<h2><span style=\"color:#000000;\"><span style=\"color:#000000;\">\u5982\u4f55\u505c\u6b62\u7ebf\u7a0b\u6216\u4efb\u52a1<\/span><\/span><\/h2>\n<p>&nbsp;<\/p>\n<h2>\u5982\u4f55\u505c\u6b62\u4e00\u4e2a\u6b63\u5728\u8fd0\u884c\u7684java\u7ebf\u7a0b<\/h2>\n<p><img decoding=\"async\" src=\"https:\/\/img.mushiming.top\/app\/mushiming_com\/cc5547ddeabf4c1cad7b7a80d7b71243.png\" =\"\" =\"\" alt=\"java\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u5426\u7ed3\u675f\u53e6\u4e00\u4e2a\u6c38\u4e0d\u505c\u6b62\u7684\u7ebf\u7a0b\u6267\u884c_\u5982\u4f55\u7ec8\u6b62\u4e00\u4e2a\u7ebf\u7a0b (https:\/\/mushiming.com\/)  \u7b2c8\u5f20\" title=\"java\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u5426\u7ed3\u675f\u53e6\u4e00\u4e2a\u6c38\u4e0d\u505c\u6b62\u7684\u7ebf\u7a0b\u6267\u884c_\u5982\u4f55\u7ec8\u6b62\u4e00\u4e2a\u7ebf\u7a0b  \u7b2c8\u5f20-\u7a46\u4e16\u660e\u535a\u5ba2\" ><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.mushiming.top\/app\/mushiming_com\/c692646288884a8182aadea57e7c3cd4.png\" =\"\" =\"\" alt=\"java\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u5426\u7ed3\u675f\u53e6\u4e00\u4e2a\u6c38\u4e0d\u505c\u6b62\u7684\u7ebf\u7a0b\u6267\u884c_\u5982\u4f55\u7ec8\u6b62\u4e00\u4e2a\u7ebf\u7a0b (https:\/\/mushiming.com\/)  \u7b2c9\u5f20\" title=\"java\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u5426\u7ed3\u675f\u53e6\u4e00\u4e2a\u6c38\u4e0d\u505c\u6b62\u7684\u7ebf\u7a0b\u6267\u884c_\u5982\u4f55\u7ec8\u6b62\u4e00\u4e2a\u7ebf\u7a0b  \u7b2c9\u5f20-\u7a46\u4e16\u660e\u535a\u5ba2\" ><\/p>\n<h2 style=\"margin-left:0px;\"><span style=\"color:#000100;\">\u4e86\u89e3Java\u4e2d\u7684\u7ebf\u7a0b\u4e2d\u65ad<\/span><\/h2>\n<p><span style=\"color:#242729;\">\u5982\u4f55\u5728Java\u4e2d\u6b63\u786e\u505c\u6b62Thread\uff1f<\/span><\/p>\n<p><span style=\"color:#242729;\">\u4f60\u5982\u4f55\u6740\u6b7bJava\u4e2d\u7684\u7ebf\u7a0b\uff1f<\/span><\/p>\n<p><span style=\"color:#0c0c0c;\">\u5982\u4f55\u5728\u8fd0\u884c\u65f6\u505c\u6b62\/\u7ec8\u6b62\u957f\u65f6\u95f4\u8fd0\u884c\u7684Java\u7ebf\u7a0b\uff1f\u8d85\u65f6 - &gt;\u53d6\u6d88 - &gt;\u4e2d\u65ad\u72b6\u6001<\/span><\/p>\n<p><span style=\"color:#242729;\">Java - \u4ece\u4e0d\u540c\u7684\u7c7b\u505c\u6b62\u7ebf\u7a0b<\/span><\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"QBCxkdgdDg\"><p>How To Stop A Thread In Java?<\/p><\/blockquote>\n<p><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;How To Stop A Thread In Java?&#8221; &#8212; Java Concept Of The Day\" src=\"https:\/\/javaconceptoftheday.com\/how-to-stop-a-thread-in-java\/embed\/#?secret=6HM9FALsvV#?secret=QBCxkdgdDg\" data-secret=\"QBCxkdgdDg\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<p style=\"margin-left:0px;\"><span style=\"color:#242729;\">\u5982\u4f55\u8d85\u65f6\u4e00\u4e2a\u7ebf\u7a0b<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>\u53c2\u8003\u300a<strong><em>Effective Java \u4e2d\u6587\u7248 \u7b2c3\u7248<\/em><\/strong>\u300b<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.mushiming.top\/app\/mushiming_com\/a901a3f0f128431689ba52cd55f251ff.png\" =\"\" =\"\" alt=\"java\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u5426\u7ed3\u675f\u53e6\u4e00\u4e2a\u6c38\u4e0d\u505c\u6b62\u7684\u7ebf\u7a0b\u6267\u884c_\u5982\u4f55\u7ec8\u6b62\u4e00\u4e2a\u7ebf\u7a0b (https:\/\/mushiming.com\/)  \u7b2c10\u5f20\" title=\"java\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u5426\u7ed3\u675f\u53e6\u4e00\u4e2a\u6c38\u4e0d\u505c\u6b62\u7684\u7ebf\u7a0b\u6267\u884c_\u5982\u4f55\u7ec8\u6b62\u4e00\u4e2a\u7ebf\u7a0b  \u7b2c10\u5f20-\u7a46\u4e16\u660e\u535a\u5ba2\" ><\/p>\n","protected":false},"excerpt":{"rendered":"java\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u5426\u7ed3\u675f\u53e6\u4e00\u4e2a\u6c38\u4e0d\u505c\u6b62\u7684\u7ebf\u7a0b\u6267\u884c_\u5982\u4f55\u7ec8\u6b62\u4e00\u4e2a\u7ebf\u7a0b\u5728Java\u4e2d\u505c\u6b62\u4e00\u4e2a\u7ebf\u7a0b\u6709\u4e09\u79cd\u529e\u6cd5\uff1a1.\u6b63\u5e38\u7ed3\u675f\u6267\u884c\uff1b2.\u53d1\u751f\u5f02...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8363"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=8363"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8363\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=8363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=8363"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=8363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}