{"id":4559,"date":"2021-09-01T11:45:01","date_gmt":"2021-09-01T03:45:01","guid":{"rendered":"http:\/\/122.152.205.50\/wordpress\/?p=4559"},"modified":"2021-09-01T11:45:01","modified_gmt":"2021-09-01T03:45:01","slug":"java%e7%ba%bf%e7%a8%8b%e6%b7%b1%e5%85%a5%e5%ad%a6%e4%b9%a0","status":"publish","type":"post","link":"http:\/\/xinyiworld.top\/wordpress_it\/?p=4559","title":{"rendered":"Java\u7ebf\u7a0b\u6df1\u5165\u5b66\u4e60"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_16 counter-hierarchy counter-decimal ez-toc-grey\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\">\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" style=\"display: none;\"><i class=\"ez-toc-glyphicon ez-toc-icon-toggle\"><\/i><\/a><\/span><\/div>\n<nav><ul class=\"ez-toc-list ez-toc-list-level-1\"><li class=\"ez-toc-page-1 ez-toc-heading-level-1\"><a class=\"ez-toc-link ez-toc-heading-1\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=4559\/#%E5%85%A8%E9%9D%A2%E6%B7%B1%E5%85%A5%E7%9A%84%E8%AE%B2%E8%A7%A3%E7%BA%BF%E7%A8%8B\" title=\"\u5168\u9762\u6df1\u5165\u7684\u8bb2\u89e3\u7ebf\u7a0b\">\u5168\u9762\u6df1\u5165\u7684\u8bb2\u89e3\u7ebf\u7a0b<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-1\"><a class=\"ez-toc-link ez-toc-heading-2\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=4559\/#%E7%9F%A5%E8%AF%86%E7%82%B9%E4%B8%80%EF%BC%9A%E7%BA%BF%E7%A8%8B%E5%88%9B%E5%BB%BA%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F\" title=\"\u77e5\u8bc6\u70b9\u4e00\uff1a\u7ebf\u7a0b\u521b\u5efa\u7684\u51e0\u79cd\u65b9\u5f0f\">\u77e5\u8bc6\u70b9\u4e00\uff1a\u7ebf\u7a0b\u521b\u5efa\u7684\u51e0\u79cd\u65b9\u5f0f<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-1\"><a class=\"ez-toc-link ez-toc-heading-3\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=4559\/#%E7%9F%A5%E8%AF%86%E7%82%B9%E4%BA%8C%EF%BC%9A%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8%EF%BC%88%E5%90%8C%E6%AD%A5%E4%B8%8E%E9%94%81%EF%BC%89\" title=\"\u77e5\u8bc6\u70b9\u4e8c\uff1a\u7ebf\u7a0b\u5b89\u5168\uff08\u540c\u6b65\u4e0e\u9501\uff09\">\u77e5\u8bc6\u70b9\u4e8c\uff1a\u7ebf\u7a0b\u5b89\u5168\uff08\u540c\u6b65\u4e0e\u9501\uff09<\/a><ul class=\"ez-toc-list-level-2\"><li class=\"ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-4\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=4559\/#1%E7%BA%BF%E7%A8%8B%E5%90%8C%E6%AD%A5%E9%97%AE%E9%A2%98%E7%9A%84%E4%BA%A7%E7%94%9F\" title=\"1.\u7ebf\u7a0b\u540c\u6b65\u95ee\u9898\u7684\u4ea7\u751f\">1.\u7ebf\u7a0b\u540c\u6b65\u95ee\u9898\u7684\u4ea7\u751f<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-5\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=4559\/#2%E5%90%8C%E6%AD%A5%E5%92%8C%E9%94%81%E5%AE%9A\" title=\"2.\u540c\u6b65\u548c\u9501\u5b9a\">2.\u540c\u6b65\u548c\u9501\u5b9a<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-6\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=4559\/#2%E9%94%81%E5%AF%B9%E8%B1%A1\" title=\"2.\u9501\u5bf9\u8c61\">2.\u9501\u5bf9\u8c61<\/a><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-1\"><a class=\"ez-toc-link ez-toc-heading-7\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=4559\/#%E7%9F%A5%E8%AF%86%E7%82%B9%E4%B8%89%EF%BC%9A%E7%BA%BF%E7%A8%8B%E9%97%B4%E7%9A%84%E4%BA%A4%E4%BA%92%E5%8D%8F%E4%BD%9C\" title=\"\u77e5\u8bc6\u70b9\u4e09\uff1a\u7ebf\u7a0b\u95f4\u7684\u4ea4\u4e92\u534f\u4f5c\">\u77e5\u8bc6\u70b9\u4e09\uff1a\u7ebf\u7a0b\u95f4\u7684\u4ea4\u4e92\u534f\u4f5c<\/a><ul class=\"ez-toc-list-level-2\"><li class=\"ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-8\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=4559\/#1wait%E3%80%81notify%E3%80%81notifyAll\" title=\"1.wait\u3001notify\u3001notifyAll\">1.wait\u3001notify\u3001notifyAll<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-9\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=4559\/#2%E7%BA%BF%E7%A8%8B%E8%B0%83%E5%BA%A6\" title=\"2.\u7ebf\u7a0b\u8c03\u5ea6\">2.\u7ebf\u7a0b\u8c03\u5ea6<\/a><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-1\"><a class=\"ez-toc-link ez-toc-heading-10\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=4559\/#%E7%9F%A5%E8%AF%86%E7%82%B9%E5%9B%9B%EF%BC%9A%E7%BA%BF%E7%A8%8B%E6%B1%A0\" title=\"\u77e5\u8bc6\u70b9\u56db\uff1a\u7ebf\u7a0b\u6c60\">\u77e5\u8bc6\u70b9\u56db\uff1a\u7ebf\u7a0b\u6c60<\/a><ul class=\"ez-toc-list-level-2\"><li class=\"ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-11\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=4559\/#%E7%BA%BF%E7%A8%8B%E6%B1%A0%E4%BD%9C%E7%94%A8\" title=\"\u7ebf\u7a0b\u6c60\u4f5c\u7528\">\u7ebf\u7a0b\u6c60\u4f5c\u7528<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-12\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=4559\/#%E7%BA%BF%E7%A8%8B%E6%B1%A0%E5%88%86%E7%B1%BB\" title=\"\u7ebf\u7a0b\u6c60\u5206\u7c7b\">\u7ebf\u7a0b\u6c60\u5206\u7c7b<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-13\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=4559\/#%E7%BA%BF%E7%A8%8B%E6%B1%A0%E7%9A%84%E9%80%82%E7%94%A8%E5%9C%BA%E6%99%AF\" title=\"\u7ebf\u7a0b\u6c60\u7684\u9002\u7528\u573a\u666f\">\u7ebf\u7a0b\u6c60\u7684\u9002\u7528\u573a\u666f<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-14\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=4559\/#%E7%BA%BF%E7%A8%8B%E6%B1%A0%E7%9A%84%E5%85%B3%E9%97%AD\" title=\"\u7ebf\u7a0b\u6c60\u7684\u5173\u95ed\">\u7ebf\u7a0b\u6c60\u7684\u5173\u95ed<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"%E5%85%A8%E9%9D%A2%E6%B7%B1%E5%85%A5%E7%9A%84%E8%AE%B2%E8%A7%A3%E7%BA%BF%E7%A8%8B\"><\/span>\u5168\u9762\u6df1\u5165\u7684\u8bb2\u89e3\u7ebf\u7a0b<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>\u7ebf\u7a0b\u8d85\u7ea7\u8be6\u89e3\uff1a<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/blog.csdn.net\/cuigx1991\/article\/details\/48219741\">http:\/\/blog.csdn.net\/cuigx1991\/article\/details\/48219741<\/a><br \/>\n\u9700\u8981\u638c\u63e1\u7684\u77e5\u8bc6\u70b9\uff1a<br \/>\n1\uff09\u7ebf\u7a0b\u7684\u6982\u5ff5<br \/>\n2\uff09\u7ebf\u7a0b\u521b\u5efa\u7684\u51e0\u79cd\u65b9\u5f0f<br \/>\n3\uff09\u7ebf\u7a0b\u7684\u72b6\u6001\u53ca\u8f6c\u6362<br \/>\n4\uff09\u5f71\u54cd\u7ebf\u7a0b\u8c03\u5ea6\u65b9\u5f0f\u7684\u51e0\u4e2a\u65b9\u6cd5<br \/>\n5\uff09\u7ebf\u7a0b\u7684\u540c\u6b65\u4e0e\u9501<br \/>\n6\uff09\u7ebf\u7a0b\u4ea4\u4e92\u534f\u4f5c<\/p>\n<h1><span class=\"ez-toc-section\" id=\"%E7%9F%A5%E8%AF%86%E7%82%B9%E4%B8%80%EF%BC%9A%E7%BA%BF%E7%A8%8B%E5%88%9B%E5%BB%BA%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F\"><\/span>\u77e5\u8bc6\u70b9\u4e00\uff1a\u7ebf\u7a0b\u521b\u5efa\u7684\u51e0\u79cd\u65b9\u5f0f<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>1.\u76f4\u63a5new Thread\uff0c\u5b9e\u73b0runnable\u65b9\u6cd5\u3002<br \/>\n2.Thread\u6784\u9020\u65b9\u6cd5\u4f20\u5165Runnable\u63a5\u53e3<br \/>\n3.\u7ebf\u7a0b\u6c60\u521b\u5efa<\/p>\n<h1><span class=\"ez-toc-section\" id=\"%E7%9F%A5%E8%AF%86%E7%82%B9%E4%BA%8C%EF%BC%9A%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8%EF%BC%88%E5%90%8C%E6%AD%A5%E4%B8%8E%E9%94%81%EF%BC%89\"><\/span>\u77e5\u8bc6\u70b9\u4e8c\uff1a\u7ebf\u7a0b\u5b89\u5168\uff08\u540c\u6b65\u4e0e\u9501\uff09<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<h2><span class=\"ez-toc-section\" id=\"1%E7%BA%BF%E7%A8%8B%E5%90%8C%E6%AD%A5%E9%97%AE%E9%A2%98%E7%9A%84%E4%BA%A7%E7%94%9F\"><\/span>1.\u7ebf\u7a0b\u540c\u6b65\u95ee\u9898\u7684\u4ea7\u751f<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u4ea7\u751f\u539f\u56e0\uff1a\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u8bbf\u95ee\u540c\u4e00\u6570\u636e\/\u65b9\u6cd5<br \/>\n\u6bd4\u5982\uff1a\u540c\u4e00\u7ebf\u7a0bA\u91cc\u7684\u65b9\u6cd5\u3001\u4ee3\u7801\u90fd\u662f\u4e00\u884c\u4e00\u884c\u6267\u884c\u7684\uff0c\u4f46\u662f\u518d\u6765\u4e2a\u7ebf\u7a0bB\uff0c\u53ef\u80fd\u7ebf\u7a0bA\u6267\u884c\u5230\u67d0\u4e2a\u65b9\u6cd5\u67d0\u4e00\u884c\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u8fd9\u65f6\u7ebf\u7a0bB\u83b7\u53d6\u4e86CPU\u6267\u884c\u6743\uff0c\u7ebf\u7a0bB\u5bf9\u7ebf\u7a0bA\u4e0b\u9762\u8981\u6267\u884c\u7684\u4e00\u884c\u4ee3\u7801\u76f8\u5173\u7684\u53d8\u91cf\u4f5c\u4e86\u6539\u52a8\uff0c\u5c31\u4f1a\u5bfc\u81f4\u5b89\u5168\u95ee\u9898\u3002<\/p>\n<h2><span class=\"ez-toc-section\" id=\"2%E5%90%8C%E6%AD%A5%E5%92%8C%E9%94%81%E5%AE%9A\"><\/span>2.\u540c\u6b65\u548c\u9501\u5b9a<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>1\uff09\u9501\u7684\u539f\u7406\uff1a\u4e00\u4e2a\u5bf9\u8c61(\u4e00\u822c\u662f\u4e00\u4e2a\u5b9e\u4f8b\uff0c\u4e5f\u53ef\u80fd\u662f\u4e00\u4e2a\u5b57\u8282\u7801)\u4e00\u628a\u9501 ...<br \/>\n\u4e00\u822c\u7684\u6587\u7ae0\u90fd\u8ba4\u4e3a\u5bf9\u8c61\u9501\u5c31\u662fthis\u6216\u8005\u5b57\u8282\u7801\uff0c\u8fd9\u4e2a\u662f\u4e0d\u51c6\u786e\u7684\u3002<strong>\u53ef\u4ee5\u662f\u4efb\u610f\u7684Object\uff0c\u6211\u8ba4\u4e3a\u4e00\u79cd\u60c5\u51b5\u662f\u4e3a\u4e86\u907f\u514d\u591a\u521b\u5efa\u4e00\u4e2aObject\uff0c\u6240\u4ee5\u5c31\u7528\u7684this\u6216\u8005\u5b57\u8282\u7801\uff1b\u53e6\u5916\u4e00\u79cd\u60c5\u51b5\u662f\u4e0d\u540c\u7684\u5bf9\u8c61\u8981\u4f7f\u7528\u540c\u4e00\u628a\u9501\uff0c\u5c31\u4e0d\u80fd\u7528this\u4e86\u3002<\/strong><\/p>\n<p>2\uff09\u540c\u6b65\u4ee3\u7801\u5757<br \/>\n\u9759\u6001\u65b9\u6cd5\u7684\u540c\u6b65\u4ee3\u7801\u5757\uff0c\u9501\u53ef\u4ee5\u7528\u5f53\u524d\u7c7b\u7684\u5b57\u8282\u7801\uff0c\u56e0\u4e3a\u9759\u6001\u65b9\u6cd5\u91cc\u65e0\u6cd5\u5f15\u7528this.<\/p>\n<pre><code class=\"line-numbers\">public static intsetName(String name){\n      synchronized(Xxx.class){\n            Xxx.name = name;\n      }\n}\n<\/code><\/pre>\n<p><strong>--synchronized(xxx)\uff1a<\/strong>\u53ef\u4ee5\u7406\u89e3\u4e3a\u7ed9\u5f53\u524d\u4ee3\u7801\u5355\u5143A\uff08\u65b9\u6cd5\u3001\u4ee3\u7801\u5757\uff09\u52a0\u4e0a\u9501xxx\uff0c\u53ea\u8981\u9501\u6ca1\u6709\u91ca\u653e\uff0c\u4efb\u4f55\u5176\u5b83\u7684\u7ebf\u7a0b\u6267\u884c\u5230\u5177\u6709\u76f8\u540c\u9501xxx\u7684\u4ee3\u7801\u5355\u5143B(\u65e0\u8bbaAB\u662f\u5426\u662f\u540c\u4e00\u4e2a\u5bf9\u8c61\u6216\u8005\u540c\u4e00\u4e2a\u7c7b,\u9501\u53ef\u4ee5\u7ed1\u5b9a\u5230\u4efb\u4f55\u7684\u6267\u884c\u8f7d\u4f53\u4e0a)\uff0c\u90fd\u4f1a\u7b49\u5f85\u4ee3\u7801\u5355\u5143A\u6267\u884c\u5b8c\u6bd5\u624d\u53bb\u6267\u884c\u3002\u66fe\u7ecf\u8001\u6bd5\u7684\u8bfe\u7a0b\u91cc\u5c31\u7528\u53bb\u6d17\u624b\u95f4\u53cd\u9501\u95e8\u4f5c\u4e86\u4e00\u4e2a\u5f62\u8c61\u7684\u6bd4\u55bb\uff0c\u9501\u4f4f\u7684\u536b\u751f\u95f4\u67d0\u4e2a\u65f6\u95f4\u6bb5\u53ea\u80fd\u7531\u4e00\u4e2a\u4eba\u4f7f\u7528\u3002<\/p>\n<blockquote><p>\n  \u770b\u4e24\u4e2a\u4ee3\u7801\u5355\u5143\u6267\u884c\u662f\u5426\u4e92\u65a5\uff0c\u9996\u5148\u770b\u5b83\u4eec\u7684\u9501\u662f\u4e0d\u662f\u540c\u4e00\u628a\u9501\u3002\n<\/p><\/blockquote>\n<p><strong>--synchronized\u91ca\u653e\u9501\u7684\u65f6\u673a\uff1a<\/strong><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/www.jianshu.com\/p\/888469ebe713\">https:\/\/www.jianshu.com\/p\/888469ebe713<\/a><\/p>\n<p><strong>--\u9501\u7684\u7c7b\u578b:<\/strong>\u9501\u4e00\u822c\u5206\u4e3a3\u5927\u7c7b\u578b\uff0c\u5bf9\u8c61\uff08Object)\u3001this\u3001class,this\u7406\u8bba\u4e0a\u6765\u8bf4\u4e5f\u662f\u5bf9\u8c61\u3002<\/p>\n<blockquote><p>\n  \u975e\u9759\u6001synchronized\u65b9\u6cd5\u7684\u9501\u662fthis<br \/>\n  \u9759\u6001synchronized\u65b9\u6cd5\u7684\u9501\u662fclass\n<\/p><\/blockquote>\n<p>\u4e0a\u9762\u8fd9\u4e2a\u7ed3\u8bba\u81ea\u5df1\u5199\u4e2a\u5c0fdemo\u5f88\u5bb9\u6613\u8bc1\u660e\uff0c\u6211\u5c31\u4e0d\u4f5c\u9610\u8ff0\u4e86\u3002<\/p>\n<p>3\uff09\u7ebf\u7a0b\u5b89\u5168\u7c7b<br \/>\n\u5f53\u4e00\u4e2a\u7c7b\u5df2\u7ecf\u5f88\u597d\u7684\u540c\u6b65\u4ee5\u4fdd\u62a4\u5b83\u7684\u6570\u636e\u65f6\uff0c\u8fd9\u4e2a\u7c7b\u5c31\u79f0\u4e3a\u201c\u7ebf\u7a0b\u5b89\u5168\u7684\u201d\u3002\u67d0\u4e2a\u7c7b\u7684\u6210\u5458\u7c7b\u662f\u5b89\u5168\u7684\uff0c\u4e0d\u4ee3\u8868\u8fd9\u4e2a\u7c7b\u5c31\u4e00\u5b9a\u5b89\u5168\u3002<\/p>\n<p>4\uff09\u6b7b\u9501<br \/>\n<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/blog.csdn.net\/nangeali\/article\/details\/80304456\">https:\/\/blog.csdn.net\/nangeali\/article\/details\/80304456<\/a><br \/>\n\u6982\u5ff5\uff1a2\u4e2a\u7ebf\u7a0b\u5728\u8fd0\u884c\u65f6\uff0c\u90fd\u4e92\u76f8\u6301\u6709\u5bf9\u65b9\u7684\u9501\uff0c\u5bfc\u81f4\u4e92\u76f8\u7b49\u5f85\u7684\u73b0\u8c61\u3002<br \/>\n\u89e3\u51b3\u65b9\u6848\uff1a<br \/>\n<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/www.cnblogs.com\/xzlf\/p\/12681525.html\">https:\/\/www.cnblogs.com\/xzlf\/p\/12681525.html<\/a><br \/>\n1\u300b\u4e0d\u8981\u5728\u540c\u4e00\u4e2a\u4ee3\u7801\u5757\u4e2d\uff0c\u6301\u6709\u591a\u4e2a\u5bf9\u8c61\u7684\u9501<\/p>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/blog.csdn.net\/sinat_41144773\/article\/details\/89476679\">https:\/\/blog.csdn.net\/sinat_41144773\/article\/details\/89476679<\/a><br \/>\n2\u300b\u52a0\u9501\u987a\u5e8f\uff1a\u5f53\u591a\u4e2a\u7ebf\u7a0b\u8981\u76f8\u540c\u7684\u4e00\u4e9b\u9501\uff0c\u4f46\u662f\u6309\u7167\u4e0d\u540c\u7684\u987a\u5e8f\u52a0\u9501\uff0c\u6b7b\u9501\u7684\u60c5\u51b5\u53d1\u751f\u7387\u8f83\u9ad8\uff0c\u5982\u679c\uff0c\u7a0b\u5e8f\u8fd0\u884c\u80fd\u786e\u4fdd\u6240\u6709\u7ebf\u7a0b\u90fd\u662f\u6309\u7167\u76f8\u540c\u7684\u987a\u5e8f\u53bb\u83b7\u5f97\u9501\uff0c\u90a3\u4e48\u6b7b\u9501\u5c31\u4e0d\u4f1a\u53d1\u751f\u3002<\/p>\n<p>3\u300b\u52a0\u9501\u65f6\u9650\uff1a\u52a0\u4e00\u4e2a\u8d85\u65f6\u65f6\u95f4\uff0c\u82e5\u4e00\u4e2a\u7ebf\u7a0b\u6ca1\u6709\u5728\u7ed9\u5b9a\u7684\u65f6\u95f4\u5185\u6210\u529f\u83b7\u53d6\u6240\u9700\u7684\u9501\uff0c\u5219\u8fdb\u884c\u56de\u9000\u64cd\u4f5c\uff0c\u5e76\u91ca\u653e\u81ea\u5df1\u672c\u8eab\u6240\u6301\u6709\u7684\u9501\uff0c\u4e00\u6bb5\u968f\u673a\u65f6\u95f4\u4e4b\u540e\uff0c\u91cd\u65b0\u53bb\u83b7\u53d6\u9501\u3002<\/p>\n<p>4\u300b\u6b7b\u9501\u68c0\u6d4b\uff1a\u6b7b\u9501\u68c0\u6d4b\uff0c\u6bcf\u5f53\u7ebf\u7a0b\u53bb\u83b7\u53d6\u9501\u7684\u65f6\u5019\uff0c\u4f1a\u5728\u7ebf\u7a0b\u548c\u9501\u76f8\u5173\u7684\u6570\u636e\u7ed3\u6784\u4e2d\u5c06\u5176\u8bb0\u4e0b\uff0c\u9664\u6b64\u4e4b\u5916\uff0c\u6bcf\u5f53\u7ebf\u7a0b\u8bf7\u6c42\u9501\uff0c\u90fd\u9700\u8981\u8bb0\u5f55\u5728\u6570\u636e\u7ed3\u6784\u4e2d\u3002\u6b7b\u9501\u68c0\u6d4b\u662f\u4e00\u4e2a\u6b7b\u9501\u907f\u514d\u673a\u5236\u3002\u4ed6\u4e3b\u8981\u9488\u5bf9\u7684\u65f6\u90a3\u4e9b\u4e0d\u53ef\u80fd\u5b9e\u73b0\u6309\u5e8f\u52a0\u9501\u5e76\u4e14\u9501\u8d85\u65f6\u4e5f\u4e0d\u53ef\u884c\u7684\u5e94\u7528\u573a\u666f\u3002<br \/>\n5\uff09volatile\u5173\u952e\u5b57<\/p>\n<h2><span class=\"ez-toc-section\" id=\"2%E9%94%81%E5%AF%B9%E8%B1%A1\"><\/span>2.\u9501\u5bf9\u8c61<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u76f8\u5f53\u4e8e\u5bf9syncronised\u7684\u5c01\u88c5\uff0c\u4f7f\u7528\u8d77\u6765\u66f4\u52a0\u7684\u65b9\u4fbf\u3002<br \/>\n1\uff09\u666e\u901a\u9501<br \/>\n2\uff09\u8bfb\u5199\u9501<br \/>\n\u8bfb\u4e0e\u8bfb\u4e0d\u4e92\u65a5\uff0c\u8bfb\u5199\u9501\u5206\u79bb\uff0c\u63d0\u9ad8\u8bfb\u5199\u6548\u7387\u3002(\u5c31\u662f\u5f53\u524d\u6709\u4e00\u4e2aRead\u7ebf\u7a0b\u83b7\u53d6\u4e86\u9501\uff0c\u5982\u679c\u8fd9\u65f6\u5019\u6709\u53e6\u5916\u4e00\u4e2aRead\u7ebf\u7a0b\u8d77\u6765\u4e86\uff0c\u8fd9\u4e2a\u7ebf\u7a0b\u4ecd\u7136\u53ef\u4ee5\u6b63\u5e38\u6267\u884c\u3002)<br \/>\n<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/www.jianshu.com\/p\/9cd5212c8841\">https:\/\/www.jianshu.com\/p\/9cd5212c8841<\/a><br \/>\n3\uff09\u4fe1\u53f7\u91cf<br \/>\n1\uff09Semaphore\u4e0d\u4e00\u5b9a\u662f\u9501\u5b9a\u67d0\u4e2a\u8d44\u6e90\uff08\u901a\u5e38\u60c5\u51b5\u4e0b\u4e0d\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\uff09\uff0c\u800c\u662f\u6d41\u7a0b\u4e0a\u7684\u6982\u5ff5\u3002<br \/>\n2\uff09\u4fe1\u53f7\u91cf\u7684\u6982\u5ff5\u4e0d\u5149\u4f5c\u7528\u4e8e\u7ebf\u7a0b\uff0c\u4e5f\u53ef\u9002\u7528\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u7684\u8fdb\u7a0b\u63a7\u5236\u3002<br \/>\n<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/www.php.cn\/java-article-407669.html\">https:\/\/www.php.cn\/java-article-407669.html<\/a><br \/>\n<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/blog.csdn.net\/shenjixiang\/article\/details\/78724705\">https:\/\/blog.csdn.net\/shenjixiang\/article\/details\/78724705<\/a><\/p>\n<h1><span class=\"ez-toc-section\" id=\"%E7%9F%A5%E8%AF%86%E7%82%B9%E4%B8%89%EF%BC%9A%E7%BA%BF%E7%A8%8B%E9%97%B4%E7%9A%84%E4%BA%A4%E4%BA%92%E5%8D%8F%E4%BD%9C\"><\/span>\u77e5\u8bc6\u70b9\u4e09\uff1a\u7ebf\u7a0b\u95f4\u7684\u4ea4\u4e92\u534f\u4f5c<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<h2><span class=\"ez-toc-section\" id=\"1wait%E3%80%81notify%E3%80%81notifyAll\"><\/span>1.wait\u3001notify\u3001notifyAll<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/blog.csdn.net\/weixin_42541254\/article\/details\/101291768\">https:\/\/blog.csdn.net\/weixin_42541254\/article\/details\/101291768<\/a><br \/>\nvoid notify()\u2014\u2014\u5524\u9192\u5728\u6b64\u5bf9\u8c61\u76d1\u89c6\u5668\u4e0a\u7b49\u5f85\u7684\u5355\u4e2a\u7ebf\u7a0b\u3002<br \/>\nvoid notifyAll()\u2014\u2014\u5524\u9192\u5728\u6b64\u5bf9\u8c61\u76d1\u89c6\u5668\u4e0a\u7b49\u5f85\u7684\u6240\u6709\u7ebf\u7a0b\u3002<br \/>\nvoid wait()\u2014\u2014\u5bfc\u81f4\u5f53\u524d\u7684\u7ebf\u7a0b\u7b49\u5f85\uff0c\u76f4\u5230\u5176\u4ed6\u7ebf\u7a0b\u8c03\u7528\u6b64\u5bf9\u8c61\u7684 notify()\u65b9\u6cd5\u6216 notifyAll()\u65b9\u6cd5\u3002<br \/>\nvoid wait(longtimeout)\u2014\u2014\u5bfc\u81f4\u5f53\u524d\u7684\u7ebf\u7a0b\u7b49\u5f85\uff0c\u76f4\u5230\u5176\u4ed6\u7ebf\u7a0b\u8c03\u7528\u6b64\u5bf9\u8c61\u7684 notify()\u65b9\u6cd5\u6216 notifyAll()\u65b9\u6cd5\uff0c\u6216\u8005\u8d85\u8fc7\u6307\u5b9a\u7684\u65f6\u95f4\u91cf\u3002<br \/>\nvoid wait(longtimeout, int nanos)\u2014\u2014\u5bfc\u81f4\u5f53\u524d\u7684\u7ebf\u7a0b\u7b49\u5f85\uff0c\u76f4\u5230\u5176\u4ed6\u7ebf\u7a0b\u8c03\u7528\u6b64\u5bf9\u8c61\u7684 notify()\u65b9\u6cd5\u6216 notifyAll()\u65b9\u6cd5\uff0c\u6216\u8005\u5176\u4ed6\u67d0\u4e2a\u7ebf\u7a0b\u4e2d\u65ad\u5f53\u524d\u7ebf\u7a0b\uff0c\u6216\u8005\u5df2\u8d85\u8fc7\u67d0\u4e2a\u5b9e\u9645\u65f6\u95f4\u91cf\u3002<\/p>\n<p><strong>wait\u3001notify\u5bf9\u9501\u7684\u5f71\u54cd<\/strong><\/p>\n<blockquote><p>\n  \u8fdb\u5165 wait()\u65b9\u6cd5\u540e\uff0c\u5f53\u524d\u7ebf\u7a0b\u91ca\u653e\u9501<br \/>\n  notify \u540e\uff0c\u5f53\u524d\u7ebf\u7a0b\u4e0d\u4f1a\u9a6c\u4e0a\u91ca\u653e\u8be5\u5bf9\u8c61\u9501\uff0cwait \u6240\u5728\u7684\u7ebf\u7a0b\u5e76\u4e0d\u80fd\u9a6c\u4e0a\u83b7\u53d6\u8be5\u5bf9\u8c61\u9501\uff0c\u8981\u7b49\u5230\u7a0b\u5e8f\u9000\u51fa synchronized \u4ee3\u7801\u5757\u540e\uff0c\u5f53\u524d\u7ebf\u7a0b\u624d\u4f1a\u91ca\u653e\u9501\uff0cwait\u6240\u5728\u7684\u7ebf\u7a0b\u4e5f\u624d\u53ef\u4ee5\u83b7\u53d6\u8be5\u5bf9\u8c61\u9501\u3002\n<\/p><\/blockquote>\n<p><strong>\u8c03\u7528\u67d0\u4e2a\u5bf9\u8c61\u7684wait\u3001notify\u7b49\u65b9\u6cd5\uff0c\u5fc5\u987b<\/strong><\/p>\n<blockquote><p>\n  1.\u5728\u5f53\u524d\u7ebf\u7a0b\u91cc\u83b7\u53d6\u8fd9\u4e2a\u5bf9\u8c61\u7684\u9501<br \/>\n  2.\u4e14\u9501\u4e00\u5b9a\u662f\u540c\u4e00\u628a\u9501\uff08\u540c\u4e00\u4e2a\u5bf9\u8c61\uff09\n<\/p><\/blockquote>\n<p>\u4e5f\u5c31\u662f\u8bf4wait()\u3001notify()\u7b49\u65b9\u6cd5\u8c03\u7528\u7684\u683c\u5f0f\u662f\u56fa\u5b9a\u7684\u3002<br \/>\n<strong>---wait()\u65b9\u6cd5\u8c03\u7528<\/strong><\/p>\n<pre><code class=\"line-numbers\">synchronized (\u9501\u5bf9\u8c61) {\n   \u9501\u5bf9\u8c61.wait();\n}\n<\/code><\/pre>\n<p>\u5982\u679c\u4e0d\u52a0synchronized\u76f4\u63a5\u8c03\u7528wait()\u65b9\u6cd5\u5c31\u4f1a\u62a5\u9519<br \/>\n```java.lang.IllegalMonitorStateException: object not locked by thread before wait()```<br \/>\n**---notify()\u65b9\u6cd5\u8c03\u7528**<\/p>\n<pre><code class=\"line-numbers\">synchronized (\u9501\u5bf9\u8c61) {\n   \u9501\u5bf9\u8c61.notify();\n}\n<\/code><\/pre>\n<p>\u5982\u679c\u4e0d\u52a0synchronized\u76f4\u63a5\u8c03\u7528notify()\u65b9\u6cd5\u5c31\u4f1a\u62a5\u9519<br \/>\n```java.lang.IllegalMonitorStateException: object not locked by thread before notify()```<\/p>\n<p>1\uff09\u7b80\u5355\u7684\u793a\u4f8b\uff1a<br \/>\n\u7b2c1\u79cd\u60c5\u51b5\uff1a\u534f\u4f5c\u7684\u7ebf\u7a0b\u5bf9\u8c61\u672c\u8eab\u4f5c\u4e3a\u9501<\/p>\n<pre><code class=\"line-numbers\">\/**\n * \u8ba1\u7b971+2+3+...+100\u7684\u548c\n *\/\npublic class ThreadB1 extends Thread {\n    int total;\n    public ThreadB1() {\n    }\n\n    public void run(){\n        synchronized (this) {\n            try {\n                Thread.sleep(100);\n            } catch (InterruptedException e) {\n                e.printStackTrace();\n            }\n\n            for (int i=0;i&lt;101;i++){\n                total+=i;\n            }\n            \/\/\uff08\u5b8c\u6210\u8ba1\u7b97\u4e86\uff09\u5524\u9192\u5728\u6b64\u5bf9\u8c61\u76d1\u89c6\u5668\u4e0a\u7b49\u5f85\u7684\u5355\u4e2a\u7ebf\u7a0b\uff0c\u5728\u672c\u4f8b\u4e2d\u7ebf\u7a0bA\u88ab\u5524\u9192\n            notify();\n        }\n    }\n}\n<\/code><\/pre>\n<pre><code class=\"line-numbers\">  private void waitTest1() {\n        ThreadB1 b=new ThreadB1();\n        \/\/\u542f\u52a8\u8ba1\u7b97\u7ebf\u7a0b\n        b.start();\n        \/\/\u7ebf\u7a0bA\u62e5\u6709b\u5bf9\u8c61\u4e0a\u7684\u9501\u3002\u7ebf\u7a0b\u4e3a\u4e86\u8c03\u7528wait()\u6216notify()\u65b9\u6cd5\uff0c\u8be5\u7ebf\u7a0b\u5fc5\u987b\u662f\u90a3\u4e2a\u5bf9\u8c61\u9501\u7684\u62e5\u6709\u8005\n        synchronized (b) {\n            try {\n                System.out.println(\"\u7b49\u5f85\u5bf9\u8c61b\u5b8c\u6210\u8ba1\u7b97......\");\n                b.wait();\n            } catch (InterruptedException e) {\n                e.printStackTrace();\n            }\n            System.out.println(\"b\u5bf9\u8c61\u8ba1\u7b97\u7684\u603b\u548c\u662f\uff1a\" + b.total);\n        }\n    }\n<\/code><\/pre>\n<p>\u7b2c2\u79cd\u5f62\u5f0f\uff1a\u521b\u5efa\u65b0\u7684\u5bf9\u8c61\u4f5c\u4e3a\u9501<\/p>\n<pre><code class=\"line-numbers\">\/**\n * \u8ba1\u7b971+2+3+...+100\u7684\u548c\n *\/\npublic class ThreadB2 extends Thread {\n    int total;\n    private Object lock;\n\n\n    public ThreadB2(Object lock) {\n        this.lock = lock;\n    }\n\n    public void run(){\n        synchronized (lock) {\n            try {\n                Thread.sleep(100);\n            } catch (InterruptedException e) {\n                e.printStackTrace();\n            }\n            for (int i=0;i&lt;101;i++){\n                total+=i;\n            }\n            \/\/\uff08\u5b8c\u6210\u8ba1\u7b97\u4e86\uff09\u5524\u9192\u5728\u6b64\u5bf9\u8c61\u76d1\u89c6\u5668\u4e0a\u7b49\u5f85\u7684\u5355\u4e2a\u7ebf\u7a0b\uff0c\u5728\u672c\u4f8b\u4e2d\u7ebf\u7a0bA\u88ab\u5524\u9192\n            lock.notify();\n        }\n    }\n}\n<\/code><\/pre>\n<pre><code class=\"line-numbers\">private void waitTest2() {\n        Object lock = new Object();\n        ThreadB2 b=new ThreadB2(lock);\n        \/\/\u542f\u52a8\u8ba1\u7b97\u7ebf\u7a0b\n        b.start();\n        \/\/\u7ebf\u7a0bA\u62e5\u6709b\u5bf9\u8c61\u4e0a\u7684\u9501\u3002\u7ebf\u7a0b\u4e3a\u4e86\u8c03\u7528wait()\u6216notify()\u65b9\u6cd5\uff0c\u8be5\u7ebf\u7a0b\u5fc5\u987b\u662f\u90a3\u4e2a\u5bf9\u8c61\u9501\u7684\u62e5\u6709\u8005\n        synchronized (lock) {\n            try {\n                System.out.println(\"\u7b49\u5f85\u5bf9\u8c61b\u5b8c\u6210\u8ba1\u7b97......\");\n                lock.wait();\n            } catch (InterruptedException e) {\n                e.printStackTrace();\n            }\n            System.out.println(\"b\u5bf9\u8c61\u8ba1\u7b97\u7684\u603b\u548c\u662f\uff1a\" + b.total);\n        }\n    }\n<\/code><\/pre>\n<p>\u300b\u300b\u300b\u5c06\u7ebf\u7a0b\u7a0d\u505a\u6539\u52a8\uff0c\u5728\u8ba1\u7b97\u548c\u4e4b\u524d\u5c31notify\u3002<\/p>\n<pre><code class=\"line-numbers\">  public void run(){\n        Log.e(TAG, \"run: \u5165\u53e3\");\n        synchronized (this) {\n            \/\/\uff08\u5b8c\u6210\u8ba1\u7b97\u4e86\uff09\u5524\u9192\u5728\u6b64\u5bf9\u8c61\u76d1\u89c6\u5668\u4e0a\u7b49\u5f85\u7684\u5355\u4e2a\u7ebf\u7a0b\uff0c\u5728\u672c\u4f8b\u4e2d\u7ebf\u7a0bA\u88ab\u5524\u9192\n            Log.e(TAG, \"run: notify\");\n            notify();\n\n            try {\n                Thread.sleep(1000);\n            } catch (InterruptedException e) {\n                e.printStackTrace();\n            }\n            Log.e(TAG, \"run: \u5f00\u59cb\u8ba1\u7b97\");\n            for (int i=0;i&lt;101;i++){\n                total+=i;\n            }\n        }\n    }\n<\/code><\/pre>\n<p>\u53d1\u73b0\u7a0b\u5e8f\u5e76\u4e0d\u4f1a\u7acb\u9a6c\u5207\u6362\u5230\u8c03\u7528wait\u7684\u7ebf\u7a0b\uff0c\u800c\u662f\u7b49notify\u7684\u7ebf\u7a0b\u6267\u884c\u5b8c\u6bd5\uff0cwait\u7684\u7ebf\u7a0b\u624d\u4f1a\u7ee7\u7eed\u6267\u884c\u3002<br \/>\n\u5982\u679cwait\u7684\u7ebf\u7a0b\u662fmain\u7ebf\u7a0b\uff0cnotify\u540e\u9762\u7684\u64cd\u4f5c\u65f6\u95f4\u5f88\u957f\uff0cmain\u7ebf\u7a0b\u4f1a\u4e00\u76f4\u7b49\u5f85\uff0c\u4f1a\u7b97\u4f5c\u662f\u963b\u585e\u4e3b\u7ebf\u7a0b\uff0c\u63d0\u793a<br \/>\n```Skipped xxx frames!  The application may be doing too much work on its main thread.```\uff0c\u6240\u4ee5\u8fd9\u4e2a\u9519\u8bef\u4e0d\u4e00\u5b9a\u5c31\u662f\u4e3b\u7ebf\u7a0b\u505a\u8017\u65f6\u64cd\u4f5c\u5bfc\u81f4\u7684\u3002<br \/>\n\uff12\uff09\u591a\u4e2a\u7ebf\u7a0b\u7b49\u5f85\u540c\u4e00\u4e2a\u5bf9\u8c61\u9501\u65f6\u4f7f\u7528notifyAll<br \/>\n 3\uff09notify\u6bd4wait\u5148\u6267\u884c\uff0c\u5bfc\u81f4wait\u65e0\u6cd5\u89e3\u9664\u3002<br \/>\n\u5bf9\u4e0a\u9762\u7684\u7b80\u5355\u793a\u4f8b\u7b2c\u4e00\u79cd\u60c5\u51b5\uff0c\u4f5c\u4e00\u4e0b\u6539\u52a8\u3002\u4f7f\u5b50\u7ebf\u7a0b\u5feb\u901f\u6267\u884c\u5b8cnotify\u65b9\u6cd5<\/p>\n<pre><code class=\"line-numbers\">public class ThreadB1 extends Thread {\n    private static final String TAG = \"ThreadB1\";\n    int total;\n    private boolean isFinish = false;\n\n    public ThreadB1() {\n    }\n\n    public void run(){\n        Log.e(TAG, \"run: \u5165\u53e3\");\n        synchronized (this) {\n\/\/            try {\n\/\/                Thread.sleep(1000);\n\/\/            } catch (InterruptedException e) {\n\/\/                e.printStackTrace();\n\/\/            }\n\/\/            Log.e(TAG, \"run: \u5f00\u59cb\u8ba1\u7b97\");\n\/\/            for (int i=0;i&lt;101;i++){\n\/\/                total+=i;\n\/\/            }\n            \/\/\uff08\u5b8c\u6210\u8ba1\u7b97\u4e86\uff09\u5524\u9192\u5728\u6b64\u5bf9\u8c61\u76d1\u89c6\u5668\u4e0a\u7b49\u5f85\u7684\u5355\u4e2a\u7ebf\u7a0b\uff0c\u5728\u672c\u4f8b\u4e2d\u7ebf\u7a0bA\u88ab\u5524\u9192\n            Log.e(TAG, \"run: notify\");\n            notify();\n            isFinish = true;\n        }\n    }\n\n    public boolean isFinish() {\n        return isFinish;\n    }\n}\n<\/code><\/pre>\n<pre><code class=\"line-numbers\">\/**\n     * \u4f7fnotify\u5148\u4e8ewait\u6267\u884c\n     *\/\n    private void waitTest11() {\n        final ThreadB1 b=new ThreadB1();\n        \/\/\u542f\u52a8\u8ba1\u7b97\u7ebf\u7a0b\n        b.start();\n        try {\n            Thread.sleep(1000);\n        } catch (InterruptedException e) {\n            e.printStackTrace();\n        }\n        \/\/\u7ebf\u7a0bA\u62e5\u6709b\u5bf9\u8c61\u4e0a\u7684\u9501\u3002\u7ebf\u7a0b\u4e3a\u4e86\u8c03\u7528wait()\u6216notify()\u65b9\u6cd5\uff0c\u8be5\u7ebf\u7a0b\u5fc5\u987b\u662f\u90a3\u4e2a\u5bf9\u8c61\u9501\u7684\u62e5\u6709\u8005\n        synchronized (b) {\n            try {\n\/\/                while (!b.isFinish()){\n                    System.out.println(\"\u7b49\u5f85\u5bf9\u8c61b\u5b8c\u6210\u8ba1\u7b97......\");\n                Timer timer = new Timer();\n                timer.schedule(new TimerTask() {\n                    @Override\n                    public void run() {\n                      System.out.println(\"\u5c1d\u8bd5notify\u4e00\u4e0b\");\n                      b.notify();\n                    }\n                },5000);\n                b.wait();\n\/\/                }\n            } catch (InterruptedException e) {\n                e.printStackTrace();\n            }\n            System.out.println(\"b\u5bf9\u8c61\u8ba1\u7b97\u7684\u603b\u548c\u662f\uff1a\" + b.total);\n        }\n    }\n<\/code><\/pre>\n<p>\u65e5\u5fd7 \u4e00\u76f4\u505c\u7559\u5728<br \/>\n<img src=\"https:\/\/upload-images.jianshu.io\/upload_images\/18328858-601b3d82c3eba49e.png?imageMogr2\/auto-orient\/strip%7CimageView2\/2\/w\/1240\" alt=\"image.png\" \/><br \/>\n\u53ef\u4ee5\u770b\u5230\u4e0a\u9762\uff0c\u5373\u4f7f\u6211\u4e8b\u5148\u4f7f\u7528\u4e86timer\u51c6\u5907notify\u89e3\u9664\u4e00\u4e0bwait\uff0c\u4e5f\u662f\u65e0\u6d4e\u4e8e\u4e8b\uff0c\u56e0\u4e3await\u9020\u6210\u5f53\u524d\u7ebf\u7a0b\u7b49\u5f85\uff0c\u800ctimer\u4e5f\u662f\u6267\u884c\u5728\u5f53\u524d\u7ebf\u7a0b\uff0c\u6240\u4ee5\u4e5f\u7b49\u5f85\u4e86\u3002<\/p>\n<p><strong>\u5b98\u65b9\u7ed9\u51fa\u7684wait\u7528\u6cd5<\/strong><\/p>\n<pre><code class=\"line-numbers\">synchronized (obj) {\n    while (&lt;condition does not hold&gt;)\n        obj.wait();\n    ... \/\/ Perform action appropriate to condition\n}\n<\/code><\/pre>\n<p>\u8fd9\u91cc\u7684while\u5224\u65ad\u5c31\u662f\u9632\u6b62notify\u6267\u884c\u5b8c\u6bd5\u4e86\uff0cwait\u624d\u6267\u884c\uff0c\u5bfc\u81f4\u5f53\u524d\u7ebf\u7a0b\u610f\u5916\u7684\u4e00\u76f4\u7b49\u5f85\u3002<\/p>\n<h2><span class=\"ez-toc-section\" id=\"2%E7%BA%BF%E7%A8%8B%E8%B0%83%E5%BA%A6\"><\/span>2.\u7ebf\u7a0b\u8c03\u5ea6<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li>1.\u4f11\u7720-sleep \uff08\u4e0d\u91ca\u653e\u7ebf\u7a0b\u9501\uff09<\/li>\n<li>2.\u4f18\u5148\u7ea7-setPriority<\/li>\n<li>3.\u8ba9\u6b65-yield\uff08\u4e0d\u91ca\u653e\u7ebf\u7a0b\u9501\uff09<\/li>\n<li>4.\u5408\u5e76-join<br \/>\n\u4f5c\u7528\uff1a\u4fdd\u8bc1\u5f53\u524d\u7ebf\u7a0b\u505c\u6b62\u6267\u884c\uff0c\u76f4\u5230\u8be5\u7ebf\u7a0b\u6240\u52a0\u5165\u7684\u7ebf\u7a0b\u5b8c\u6210\u4e3a\u6b62\u3002\u4f7f\u5f97\u5f53\u524d\u7ebf\u7a0b\u91cc\u5f00\u542f\u7684\u65b0\u7ebf\u7a0b\u4e4b\u95f4\u7684\u5e76\u884c\u6267\u884c\u53d8\u4e3a\u4e32\u884c\u6267\u884c\u3002<\/li>\n<\/ul>\n<pre><code class=\"line-numbers\">  ThreadJoinTest t1 = new ThreadJoinTest(\"\u5c0f\u660e\");\n        ThreadJoinTest t2 = new ThreadJoinTest(\"\u5c0f\u4e1c\");\n        t1.start();\n        \/**join\u7684\u610f\u601d\u662f\u4f7f\u5f97\u653e\u5f03\u5f53\u524d\u7ebf\u7a0b\u7684\u6267\u884c\uff0c\u5e76\u8fd4\u56de\u5bf9\u5e94\u7684\u7ebf\u7a0b\uff0c\u4f8b\u5982\u4e0b\u9762\u4ee3\u7801\u7684\u610f\u601d\u5c31\u662f\uff1a\n         \u7a0b\u5e8f\u5728main\u7ebf\u7a0b\u4e2d\u8c03\u7528t1\u7ebf\u7a0b\u7684join\u65b9\u6cd5\uff0c\u5219main\u7ebf\u7a0b\u653e\u5f03cpu\u63a7\u5236\u6743\uff0c\u5e76\u8fd4\u56det1\u7ebf\u7a0b\u7ee7\u7eed\u6267\u884c\u76f4\u5230\u7ebf\u7a0bt1\u6267\u884c\u5b8c\u6bd5\n         \u6240\u4ee5\u7ed3\u679c\u662ft1\u7ebf\u7a0b\u6267\u884c\u5b8c\u540e\uff0c\u624d\u5230\u4e3b\u7ebf\u7a0b\u6267\u884c\uff0c\u76f8\u5f53\u4e8e\u5728main\u7ebf\u7a0b\u4e2d\u540c\u6b65t1\u7ebf\u7a0b\uff0ct1\u6267\u884c\u5b8c\u4e86\uff0cmain\u7ebf\u7a0b\u624d\u6709\u6267\u884c\u7684\u673a\u4f1a\n         *\/\n        t1.join();\n        t2.start();\n<\/code><\/pre>\n<ul>\n<li>5.\u5b88\u62a4-deamon (\u614e\u7528)<\/li>\n<li>6.wait\/notify<br \/>\n\u5e76\u53d1\u534f\u4f5c-\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u578b<\/li>\n<\/ul>\n<h1><span class=\"ez-toc-section\" id=\"%E7%9F%A5%E8%AF%86%E7%82%B9%E5%9B%9B%EF%BC%9A%E7%BA%BF%E7%A8%8B%E6%B1%A0\"><\/span>\u77e5\u8bc6\u70b9\u56db\uff1a\u7ebf\u7a0b\u6c60<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<h2><span class=\"ez-toc-section\" id=\"%E7%BA%BF%E7%A8%8B%E6%B1%A0%E4%BD%9C%E7%94%A8\"><\/span>\u7ebf\u7a0b\u6c60\u4f5c\u7528<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>1\uff09\u590d\u7528\u7ebf\u7a0b\uff0c\u907f\u514d\u521b\u5efa\u5f00\u9500\u3002<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E7%BA%BF%E7%A8%8B%E6%B1%A0%E5%88%86%E7%B1%BB\"><\/span>\u7ebf\u7a0b\u6c60\u5206\u7c7b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>1\uff09\u56fa\u5b9a\u5927\u5c0f\u7684\u7ebf\u7a0b\u6c60<br \/>\n2\uff09\u5355\u4e00\u4efb\u52a1\u7ebf\u7a0b\u6c60<br \/>\n3\uff09\u53ef\u53d8\u5c3a\u5bf8\u7ebf\u7a0b\u6c60<br \/>\n4\uff09\u5ef6\u8fdf\u7ebf\u7a0b\u6c60<br \/>\n<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/blog.csdn.net\/h610968110\/article\/details\/78894513\">https:\/\/blog.csdn.net\/h610968110\/article\/details\/78894513<\/a><\/p>\n<p>5\uff09\u5355\u4efb\u52a1\u5ef6\u8fdf\u7ebf\u7a0b\u6c60<br \/>\n6\uff09\u81ea\u5b9a\u4e49\u7ebf\u7a0b\u6c60<br \/>\n7\uff09\u5e26\u8fd4\u56de\u503c\u7684\u7ebf\u7a0b\uff08\u4f9d\u8d56\u4e8e\u7ebf\u7a0b\u6c60\uff09<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E7%BA%BF%E7%A8%8B%E6%B1%A0%E7%9A%84%E9%80%82%E7%94%A8%E5%9C%BA%E6%99%AF\"><\/span>\u7ebf\u7a0b\u6c60\u7684\u9002\u7528\u573a\u666f<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/blog.csdn.net\/qq_43692920\/article\/details\/90266704\">https:\/\/blog.csdn.net\/qq_43692920\/article\/details\/90266704<\/a><\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E7%BA%BF%E7%A8%8B%E6%B1%A0%E7%9A%84%E5%85%B3%E9%97%AD\"><\/span>\u7ebf\u7a0b\u6c60\u7684\u5173\u95ed<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/www.cnblogs.com\/aspirant\/p\/10265863.html\">https:\/\/www.cnblogs.com\/aspirant\/p\/10265863.html<\/a><br \/>\nshutdown\u4e0eshutDownNow\u65b9\u6cd5<\/p>\n<button class=\"simplefavorite-button\" data-postid=\"4559\" data-siteid=\"1\" data-groupid=\"1\" data-favoritecount=\"0\" style=\"\">\u6536\u85cf <i class=\"sf-icon-star-empty\"><\/i><\/button>","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55 \u5168\u9762\u6df1\u5165\u7684\u8bb2\u89e3\u7ebf\u7a0b\u77e5\u8bc6\u70b9\u4e00\uff1a\u7ebf\u7a0b\u521b\u5efa\u7684\u51e0\u79cd\u65b9\u5f0f\u77e5\u8bc6\u70b9\u4e8c\uff1a\u7ebf\u7a0b\u5b89\u5168\uff08\u540c\u6b65\u4e0e\u9501\uff091.\u7ebf\u7a0b\u540c\u6b65\u95ee\u9898\u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[31],"tags":[],"_links":{"self":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/4559"}],"collection":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4559"}],"version-history":[{"count":1,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/4559\/revisions"}],"predecessor-version":[{"id":4560,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/4559\/revisions\/4560"}],"wp:attachment":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4559"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4559"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4559"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}