{"id":3544,"date":"2018-12-12T17:59:36","date_gmt":"2018-12-12T09:59:36","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=3544"},"modified":"2018-12-12T17:59:36","modified_gmt":"2018-12-12T09:59:36","slug":"%e4%ba%86%e8%a7%a3%e5%a4%9a%e7%ba%bf%e7%a8%8b%ef%bc%8c%e5%85%88%e4%bb%8e%e5%9b%be%e4%ba%86%e8%a7%a3%e7%ba%bf%e7%a8%8b%e7%9a%84%e5%9f%ba%e6%9c%ac%e7%8a%b6%e6%80%81","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=3544","title":{"rendered":"\u4e86\u89e3\u591a\u7ebf\u7a0b\uff0c\u5148\u4ece\u201c\u56fe\u201d\u4e86\u89e3\u7ebf\u7a0b\u7684\u57fa\u672c\u72b6\u6001"},"content":{"rendered":"<p>\n\t\u6700\u8fd1\u6211\u770b\u4e86\u6df7\u6c8c\u5927\u5b66\u91cc\u5f20\u9996\u665f\u6559\u6388\u7684\u6f14\u8bb2\uff0c\u5f20\u6559\u6388\u59cb\u7ec8\u5f3a\u8c03\u4e00\u4e2a&ldquo;\u5927\u9053\u81f3\u7b80&rdquo;\u7684\u81f3\u7406\u540d\u8a00\u3002\u56e0\u4e3a\u6240\u6709\u7684\u79d1\u5b66\u53d1\u73b0\uff0c\u6280\u672f\u8fdb\u6b65\u90fd\u662f\u4ece\u7b80\u5355\u7684\u57fa\u7840\u77e5\u8bc6\u5f97\u6765\u7684\u3002\u6bd4\u5982\uff1a\u52fe\u80a1\u5b9a\u7406\uff0c\u6b27\u51e0\u91cc\u5f97\u51e0\u4f55\uff0c\u4e07\u6709\u5f15\u529b\uff0c\u76f8\u5bf9\u8bba\u7b49\uff0c\u90fd\u662f\u57fa\u4e8e\u81ea\u7136\u754c\u7684\u81ea\u7136\u4e8b\u5b9e\u5f97\u51fa\u7684\u3002\n<\/p>\n<p>\n\t\u53cd\u5e94\u5230\u6211\u4eec\u7684\u7f16\u7a0b\u4e16\u754c\u3002\u6240\u6709\u7684\u601d\u60f3\u548c\u5b9e\u8df5\u90fd\u662f\u7531\u6700\u7b80\u5355\u7684\u57fa\u7840\u77e5\u8bc6\u6784\u6210\u3002\u9ad8\u5e76\u53d1\uff0c\u591a\u7ebf\u7a0b\uff0c\u5206\u5e03\u5f0f\u7b49\u6280\u672f\u90fd\u662f\u5728\u57fa\u7840\u7684\u7f16\u7a0b\u77e5\u8bc6\u4e0a\u5f97\u5230\u5347\u534e\u7684\u3002\n<\/p>\n<p>\n\t\u5f20\u6559\u6388\u8fd8\u5f3a\u8c03\uff0c\u72c4\u62c9\u514b\u7406\u8bba\u5c31\u662f\u6709\u72c4\u62c9\u514b\u5728\u770b\u5230\u6570\u5b66\u4e2d\u7684\u5f00\u6839\u60f3\u5230\u7684\uff0c4 \u5f00\u6839\u662f 2 \u548c -2\uff0c\u7531\u6b64\u8054\u60f3\u5230\u4e86&ldquo;\u4e00\u5207\u7c92\u5b50\u5747\u6709\u5176\u76f8\u5e94\u7684\u53cd\u7c92\u5b50&rdquo;\u7684\u731c\u60f3\uff0c\u8fd9\u4e00\u731c\u60f3\u540e\u6765\u88ab\u8bc1\u5b9e\u3002\n<\/p>\n<p>\n\t\u8fd9\u5c31\u662f\u5927\u9053\u81f3\u7b80\u3002\n<\/p>\n<p>\n\t\u5728\u7f16\u7a0b\u7684\u4e16\u754c\u4e2d\uff0c\u4e0d\u7ba1\u591a\u7ebf\u7a0b\u6709\u591a\u96be\uff0c\u5e76\u53d1\u6709\u591a\u9ad8\uff0c\u90fd\u79bb\u4e0d\u6211\u4eec\u7684\u57fa\u7840\u77e5\u8bc6\u3002\u8981\u5b66\u4e60\u597d\u591a\u7ebf\u7a0b\uff0c\u5c31\u5fc5\u987b\u591a\u7ebf\u7a0b\u7684\u57fa\u672c\u72b6\u6001\u6709\u8db3\u591f\u7684\u7406\u89e3\u3002\u672c\u6587\u6211\u4eec\u4e00\u8d77\u4ece&ldquo;\u56fe&rdquo;\u6765\u770b\u770b\u7ebf\u7a0b\u7684\u57fa\u672c\u72b6\u6001\u5427\u3002\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"Java \u4e2d\u7684\u7ebf\u7a0b\u72b6\u6001\u8f6c\u5316\u56fe\" src=\"https:\/\/camo.githubusercontent.com\/5b764ff5af6204f82c7ae6237b20c41f9505aef8\/68747470733a2f2f757365722d676f6c642d63646e2e786974752e696f2f323031382f382f392f313635316631396437633465393361333f773d38373626683d34393226663d706e6726733d313238303932\" style=\"width: 876px;height: 492px\" \/>\n<\/p>\n<ul>\n<li>\n\t\t\u65b0\u5efa(new)\uff1a\u65b0\u521b\u5efa\u4e86\u4e00\u4e2a\u7ebf\u7a0b\u5bf9\u8c61\u3002\n\t<\/li>\n<li>\n\t\t\u53ef\u8fd0\u884c(runnable)\uff1a\u7ebf\u7a0b\u5bf9\u8c61\u521b\u5efa\u540e\uff0c\u5176\u4ed6\u7ebf\u7a0b(\u6bd4\u5982main\u7ebf\u7a0b\uff09\u8c03\u7528\u4e86\u8be5\u5bf9\u8c61\u7684start()\u65b9\u6cd5\u3002\u8be5\u72b6\u6001\u7684\u7ebf\u7a0b\u4f4d\u4e8e\u53ef\u8fd0\u884c\u7ebf\u7a0b\u6c60\u4e2d\uff0c\u7b49\u5f85\u88ab\u7ebf\u7a0b\u8c03\u5ea6\u9009\u4e2d\uff0c\u83b7 \u53d6cpu\u7684\u4f7f\u7528\u6743\u3002\n\t<\/li>\n<li>\n\t\t\u8fd0\u884c(running)\uff1a\u53ef\u8fd0\u884c\u72b6\u6001(runnable)\u7684\u7ebf\u7a0b\u83b7\u5f97\u4e86cpu\u65f6\u95f4\u7247\uff08timeslice\uff09\uff0c\u6267\u884c\u7a0b\u5e8f\u4ee3\u7801\u3002\n\t<\/li>\n<li>\n\t\t\u963b\u585e(block)\uff1a\u963b\u585e\u72b6\u6001\u662f\u6307\u7ebf\u7a0b\u56e0\u4e3a\u67d0\u79cd\u539f\u56e0\u653e\u5f03\u4e86cpu\u4f7f\u7528\u6743\uff0c\u4e5f\u5373\u8ba9\u51fa\u4e86cpu timeslice\uff0c\u6682\u65f6\u505c\u6b62\u8fd0\u884c\u3002\u76f4\u5230\u7ebf\u7a0b\u8fdb\u5165\u53ef\u8fd0\u884c(runnable)\u72b6\u6001\uff0c\u624d\u6709 \u673a\u4f1a\u518d\u6b21\u83b7\u5f97cpu timeslice\u8f6c\u5230\u8fd0\u884c(running)\u72b6\u6001\u3002\u963b\u585e\u7684\u60c5\u51b5\u5206\u4e09\u79cd\uff1a (\u4e00). \u7b49\u5f85\u963b\u585e\uff1a\u8fd0\u884c(running)\u7684\u7ebf\u7a0b\u6267\u884co.wait()\u65b9\u6cd5\uff0cJVM\u4f1a\u628a\u8be5\u7ebf\u7a0b\u653e \u5165\u7b49\u5f85\u961f\u5217(waitting queue)\u4e2d\u3002 (\u4e8c). \u540c\u6b65\u963b\u585e\uff1a\u8fd0\u884c(running)\u7684\u7ebf\u7a0b\u5728\u83b7\u53d6\u5bf9\u8c61\u7684\u540c\u6b65\u9501\u65f6\uff0c\u82e5\u8be5\u540c\u6b65\u9501 \u88ab\u522b\u7684\u7ebf\u7a0b\u5360\u7528\uff0c\u5219JVM\u4f1a\u628a\u8be5\u7ebf\u7a0b\u653e\u5165\u9501\u6c60(lock pool)\u4e2d\u3002 (\u4e09). \u5176\u4ed6\u963b\u585e: \u8fd0\u884c(running)\u7684\u7ebf\u7a0b\u6267\u884cThread.sleep(long ms)\u6216t.join()\u65b9\u6cd5\uff0c\u6216\u8005\u53d1\u51fa\u4e86I\/O\u8bf7\u6c42\u65f6\uff0cJVM\u4f1a\u628a\u8be5\u7ebf\u7a0b\u7f6e\u4e3a\u963b\u585e\u72b6\u6001\u3002\u5f53sleep()\u72b6\u6001\u8d85\u65f6join()\u7b49\u5f85\u7ebf\u7a0b\u7ec8\u6b62\u6216\u8005\u8d85\u65f6\u3001\u6216\u8005I\/O\u5904\u7406\u5b8c\u6bd5\u65f6\uff0c\u7ebf\u7a0b\u91cd\u65b0\u8f6c\u5165\u53ef\u8fd0\u884c(runnable)\u72b6\u6001\u3002\n\t<\/li>\n<li>\n\t\t\u6b7b\u4ea1(dead)\uff1a\u7ebf\u7a0brun()\u3001main()\u65b9\u6cd5\u6267\u884c\u7ed3\u675f\uff0c\u6216\u8005\u56e0\u5f02\u5e38\u9000\u51fa\u4e86run()\u65b9\u6cd5\uff0c\u5219\u8be5\u7ebf\u7a0b\u7ed3\u675f\u751f\u547d\u5468\u671f\u3002\u6b7b\u4ea1\u7684\u7ebf\u7a0b\u4e0d\u53ef\u518d\u6b21\u590d\u751f\u3002\n\t<\/li>\n<\/ul>\n<p>\n\t\u6709\u4eba\u628a\u7ebf\u7a0b\u72b6\u6001\u7684\u8f6c\u5316\u8fc7\u7a0b\u901a\u8fc7\u65e9\u8d77\u5750\u5730\u94c1\u6765\u505a\u4e86\u4e00\u4e2a\u6bd4\u55bb\uff0c\u6211\u89c9\u5f97\u975e\u5e38\u7684\u5f62\u8c61\u3002\u63a8\u8350\u7ed9\u5927\u5bb6\uff1a\u4ece\u65b0\u5efa\u72b6\u6001 -&gt; \u5c31\u7eea\u72b6\u6001 -&gt; \u963b\u585e\u72b6\u6001 -&gt; \u8fd0\u884c\u72b6\u6001 -&gt; \u6b7b\u4ea1\u72b6\u6001\u3002\n<\/p>\n<p>\n\t\u65b0\u5efa\u72b6\u6001 New\uff1a\u65b0\u7684\u4e00\u5929<br \/>\n\t\u51c6\u5907\u5c31\u7eea start\uff1a\u95f9\u949f\u54cd\u4e86<br \/>\n\tsleeping\uff1a\u8fd8\u6ca1\u8d77\u5e8a\uff0c\u8bf7\u7ed9\u6211\u8d77\u5e8a\u7684\u52c7\u6c14<br \/>\n\tRunnable\uff1a\u8d77\u5e8a\u6536\u62fe\u597d\u4e86\uff0c\u968f\u65f6\u53ef\u4ee5\u5750\u5730\u94c1\u51fa\u53d1<br \/>\n\tWaiting\uff1a\u7b49\u5730\u94c1\u6765<br \/>\n\tI\/O\u963b\u585e\uff1a\u5730\u94c1\u6765\u4e86\uff0c\u4f46\u8981\u6392\u961f\u4e0a\u5730\u94c1<br \/>\n\tsynchronized \u963b\u585e\uff1a\u4e0a\u4e86\u5730\u94c1\uff0c\u53d1\u73b0\u6682\u65f6\u6ca1\u5ea7\u4f4d<br \/>\n\tRunning\uff1a\u5730\u94c1\u4e0a\u627e\u5230\u5ea7\u4f4d<br \/>\n\tDead\uff1a\u5230\u8fbe\u76ee\u7684\u5730\n<\/p>\n<p>\n\t\u4e16\u754c\u4e0a\u8d8a\u662f\u590d\u6742\u7684\u95ee\u9898\u8d8a\u6709\u4e00\u4e2a\u7b80\u5355\u7684\u89e3\uff1b\u8d8a\u662f\u5927\u7684\u9053\u7406\u8d8a\u662f\u7b80\u5355\u800c\u6734\u7d20\u7684\uff01\u6240\u8c13&ldquo;\u5927\u9053\u81f3\u7b80&rdquo;\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=3544\">\u4e86\u89e3\u591a\u7ebf\u7a0b\uff0c\u5148\u4ece\u201c\u56fe\u201d\u4e86\u89e3\u7ebf\u7a0b\u7684\u57fa\u672c\u72b6\u6001<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u6211\u770b\u4e86\u6df7\u6c8c\u5927\u5b66\u91cc\u5f20\u9996\u665f\u6559\u6388\u7684\u6f14\u8bb2\uff0c\u5f20\u6559\u6388\u59cb\u7ec8\u5f3a\u8c03\u4e00\u4e2a&ldquo;\u5927\u9053\u81f3\u7b80&rdquo;\u7684\u81f3\u7406\u540d\u8a00\u3002\u56e0\u4e3a\u6240 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[565,983,202,883,1104],"class_list":["post-3544","post","type-post","status-publish","format-standard","hentry","category-java","tag-java-","tag-shiro-","tag-locked","tag-883","tag-1104"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3544","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3544"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3544\/revisions"}],"predecessor-version":[{"id":3545,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3544\/revisions\/3545"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3544"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3544"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3544"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}