{"id":35977,"date":"2024-11-26T16:40:57","date_gmt":"2024-11-26T08:40:57","guid":{"rendered":"https:\/\/fwq.ai\/blog\/35977\/"},"modified":"2024-11-26T16:40:57","modified_gmt":"2024-11-26T08:40:57","slug":"%e5%a4%9a%e7%ba%bf%e7%a8%8b%e7%a8%8b%e5%ba%8f%e4%b8%ad%ef%bc%8c%e4%b8%ba%e4%bb%80%e4%b9%88%e7%ba%bf%e7%a8%8b%e6%89%a7%e8%a1%8c%e9%a1%ba%e5%ba%8f%e4%b8%8d%e6%80%bb%e6%98%af%e5%92%8c%e4%bb%a3%e7%a0%81","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/35977\/","title":{"rendered":"\u591a\u7ebf\u7a0b\u7a0b\u5e8f\u4e2d\uff0c\u4e3a\u4ec0\u4e48\u7ebf\u7a0b\u6267\u884c\u987a\u5e8f\u4e0d\u603b\u662f\u548c\u4ee3\u7801\u987a\u5e8f\u4e00\u81f4\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173085934148390.jpg\" class=\"aligncenter\" title=\"\u591a\u7ebf\u7a0b\u7a0b\u5e8f\u4e2d\uff0c\u4e3a\u4ec0\u4e48\u7ebf\u7a0b\u6267\u884c\u987a\u5e8f\u4e0d\u603b\u662f\u548c\u4ee3\u7801\u987a\u5e8f\u4e00\u81f4\uff1f\u63d2\u56fe\" alt=\"\u591a\u7ebf\u7a0b\u7a0b\u5e8f\u4e2d\uff0c\u4e3a\u4ec0\u4e48\u7ebf\u7a0b\u6267\u884c\u987a\u5e8f\u4e0d\u603b\u662f\u548c\u4ee3\u7801\u987a\u5e8f\u4e00\u81f4\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u7ebf\u7a0b\u6267\u884c\u987a\u5e8f<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u5728\u5982\u4e0b\u4ee3\u7801\u4e2d\uff0c\u4e3a\u4ec0\u4e48\u7ebf\u7a0b\u6267\u884c\u987a\u5e8f\u4e0e\u9884\u60f3\u4e0d\u7b26\uff1f<\/p>\n<pre>public class testmythread {\n    public static void main(string[] args) {\n        myrunnable myrunnable = new myrunnable();\n        thread thread = new thread(myrunnable, \"myrunnable\");\n        thread.start();\n        system.out.println(thread.getname());\n    }\n}\n\npublic class myrunnable implements runnable {\n    @override\n    public void run() {\n        for (int i = 0; i &lt; 10; i++) {\n            system.out.println(\"myrunnable\" + new date().gettime() + \"---\" + i + \"--count\");\n        }\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u7b54\u6848\uff1a<\/strong><\/p>\n<p>\u5b9e\u9645\u4e0a\uff0c\u7ebf\u7a0b\u6267\u884c\u987a\u5e8f\u4e0e\u4ee3\u7801\u987a\u5e8f\u65e0\u5173\u3002\u591a\u7ebf\u7a0b\u7a0b\u5e8f\u662f\u5e76\u53d1\u7684\uff0c\u8fd9\u610f\u5473\u7740\u4e0d\u540c\u7684\u7ebf\u7a0b\u53ef\u4ee5\u540c\u65f6\u6267\u884c\uff0c\u5e76\u4e14\u6267\u884c\u987a\u5e8f\u53ef\u80fd\u4f1a\u56e0\u7cfb\u7edf\u800c\u5f02\u3002\u5728\u7ed9\u5b9a\u7684\u793a\u4f8b\u4e2d\uff0c\u53ef\u80fd\u51fa\u73b0\u4ee5\u4e0b\u6267\u884c\u987a\u5e8f\uff1a<\/p>\n<ol>\n<li>mn \u65b9\u6cd5\u4e2d\u7684\u6253\u5370\u8bed\u53e5\u6267\u884c\uff0c\u8f93\u51fa\u7ebf\u7a0b\u540d\u79f0\u3002<\/li>\n<li>myrunnable \u7c7b\u7684 run \u65b9\u6cd5\u6267\u884c\uff0c\u8f93\u51fa\u8ba1\u6570\u6d88\u606f\u3002<\/li>\n<\/ol>\n<p>\u4f46\u662f\uff0c\u7531\u4e8e\u7ebf\u7a0b\u8c03\u5ea6\u5668\u7684\u4e0d\u53ef\u9884\u6d4b\u6027\uff0c\u5b9e\u9645\u6267\u884c\u987a\u5e8f\u53ef\u80fd\u4f1a\u6709\u6240\u4e0d\u540c\uff0c\u5373 myrunnable \u7ebf\u7a0b\u53ef\u80fd\u5148\u6267\u884c\uff0c\u7136\u540e\u518d\u8f93\u51fa\u7ebf\u7a0b\u540d\u79f0\u3002<\/p>\n<p><strong>\u539f\u56e0\uff1a<\/strong><\/p>\n<p>\u8fd9\u662f\u56e0\u4e3a java \u4f7f\u7528\u65f6\u95f4\u7247\u8c03\u5ea6\u5668\uff0c\u5b83\u5728\u4e0d\u540c\u7684\u7ebf\u7a0b\u4e4b\u95f4\u5171\u4eab\u65f6\u95f4\u3002\u5f53\u4e00\u4e2a\u7ebf\u7a0b\u6267\u884c\u65f6\uff0c\u53ef\u80fd\u4f1a\u88ab\u4e2d\u65ad\u5e76\u5141\u8bb8\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u6267\u884c\u3002<\/p>\n<p><strong>\u8c03\u6574\u6253\u5370\u8f93\u51fa\u4ee5\u663e\u5f0f\u663e\u793a\u7ebf\u7a0b\u6267\u884c\u987a\u5e8f\uff1a<\/strong><\/p>\n<p>\u4e3a\u4e86\u66f4\u660e\u786e\u5730\u663e\u793a\u7ebf\u7a0b\u6267\u884c\u987a\u5e8f\uff0c\u53ef\u4ee5\u5728 myrunnable \u7c7b\u4e2d\u6dfb\u52a0\u4e00\u4e2a println \u8bed\u53e5\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>public class MyRunnable implements Runnable {\n    @Override\n    public void run() {\n        System.out.println(\"Thread \" + Thread.currentThread().getName() + \" started\");\n        for (int i = 0; i &lt; 10; i++) {\n            System.out.println(\"MyRunnable\" + new Date().getTime() + \"---\" + i + \"--count\");\n        }\n        System.out.println(\"Thread \" + Thread.currentThread().getName() + \" finished\");\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u6837\uff0c\u4f60\u5c31\u53ef\u4ee5\u89c2\u5bdf\u5230\u54ea\u4e2a\u7ebf\u7a0b\u5728\u7279\u5b9a\u65f6\u95f4\u8f93\u51fa\u6d88\u606f\uff0c\u4ece\u800c\u8fdb\u4e00\u6b65\u4e86\u89e3\u7ebf\u7a0b\u6267\u884c\u987a\u5e8f\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u591a\u7ebf\u7a0b\u7a0b\u5e8f\u4e2d\uff0c\u4e3a\u4ec0\u4e48\u7ebf\u7a0b\u6267\u884c\u987a\u5e8f\u4e0d\u603b\u662f\u548c\u4ee3\u7801\u987a\u5e8f\u4e00\u81f4\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7ebf\u7a0b\u6267\u884c\u987a\u5e8f \u95ee\u9898\uff1a \u5728\u5982\u4e0b\u4ee3\u7801\u4e2d\uff0c\u4e3a\u4ec0\u4e48\u7ebf\u7a0b\u6267\u884c\u987a\u5e8f\u4e0e\u9884\u60f3\u4e0d\u7b26\uff1f public class testmythread { public static void main(string[] args) { myrunnable myrunnable = new myrunnable(); thread thread = new thread(myrunnable, &#8220;myrunnable&#8221;); thread.start(); system.out.println(thread.getname()); } } public class myrunnable implements runnable { @override public void run() { for (int i = 0; i &lt; 10; i++) { system.out.println(&#8220;myrunnable&#8221; + new date().gettime() + &#8220;&#8212;&#8221; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-35977","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35977","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=35977"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35977\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=35977"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=35977"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=35977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}