{"id":35173,"date":"2024-11-26T10:42:51","date_gmt":"2024-11-26T02:42:51","guid":{"rendered":"https:\/\/fwq.ai\/blog\/35173\/"},"modified":"2024-11-26T10:42:51","modified_gmt":"2024-11-26T02:42:51","slug":"java-%e4%b8%ad-wait-%e5%92%8c-sleep-%e6%96%b9%e6%b3%95%ef%bc%9a%e5%bc%82%e5%90%8c%e7%82%b9%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/35173\/","title":{"rendered":"Java \u4e2d wait() \u548c sleep() \u65b9\u6cd5\uff1a\u5f02\u540c\u70b9\u8be6\u89e3"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173063189897830.jpg\" class=\"aligncenter\" title=\"Java \u4e2d wait() \u548c sleep() \u65b9\u6cd5\uff1a\u5f02\u540c\u70b9\u8be6\u89e3\u63d2\u56fe\" alt=\"Java \u4e2d wait() \u548c sleep() \u65b9\u6cd5\uff1a\u5f02\u540c\u70b9\u8be6\u89e3\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u4e2d wt() \u548c sleep() \u65b9\u6cd5\u7684\u5f02\u540c<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0cwait() \u548c sleep() \u90fd\u662f\u7528\u4e8e\u63a7\u5236\u7ebf\u7a0b\u6267\u884c\u7684\u5e38\u7528\u65b9\u6cd5\uff0c\u4f46\u5b83\u4eec\u4e4b\u95f4\u5b58\u5728\u7740\u4e00\u4e9b\u91cd\u8981\u7684\uff1a<\/p>\n<p><strong>\u76f8\u540c\u70b9\uff1a<\/strong><\/p>\n<ul>\n<li>\u5b83\u4eec\u90fd\u53ef\u4ee5\u5728\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\u8ba9\u7ebf\u7a0b\u963b\u585e\u3002<\/li>\n<li>\u5b83\u4eec\u90fd\u53ef\u4ee5\u54cd\u5e94 interrupt \u4e2d\u65ad\uff0c\u5e76\u5728\u7b49\u5f85\u8fc7\u7a0b\u4e2d\u629b\u51fa InterruptedException \u5f02\u5e38\u3002<\/li>\n<\/ul>\n<p><strong>\u4e0d\u540c\u70b9\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li>\n<p><strong>\u83b7\u53d6\u548c\u91ca\u653e\u9501\uff1a<\/strong><\/p>\n<ul>\n<li>wait() \u65b9\u6cd5\u53ea\u80fd\u5728 synchronized \u4fdd\u62a4\u7684\u4ee3\u7801\u4e2d\u4f7f\u7528\uff0c\u56e0\u4e3a wait() \u64cd\u4f5c\u9700\u8981\u6301\u6709\u5bf9\u8c61\u7684\u9501\u3002\u800c sleep() \u65b9\u6cd5\u5219\u6ca1\u6709\u8fd9\u4e2a\u8981\u6c42\u3002<\/li>\n<li>\u6267\u884c wait() \u65b9\u6cd5\u65f6\uff0c\u7ebf\u7a0b\u4f1a\u4e3b\u52a8\u91ca\u653e\u5bf9\u8c61\u7684\u9501\uff0c\u800c\u6267\u884c sleep() \u65b9\u6cd5\u65f6\u5e76\u4e0d\u4f1a\u91ca\u653e\u9501\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8bbe\u7f6e\u65f6\u95f4\uff1a<\/strong><\/p>\n<ul>\n<li>sleep() \u65b9\u6cd5\u8981\u6c42\u5fc5\u987b\u6307\u5b9a\u4e00\u4e2a\u65f6\u95f4\u503c\uff0c\u5230\u65f6\u540e\u81ea\u52a8\u6062\u590d\u6267\u884c\u3002\u800c wait() \u65b9\u6cd5\u53ef\u4ee5\u4e0d\u6307\u5b9a\u65f6\u95f4\u503c\uff0c\u6b64\u65f6\u7ebf\u7a0b\u5c06\u6c38\u4e45\u7b49\u5f85\uff0c\u76f4\u5230\u6536\u5230\u901a\u77e5\u6216\u4e2d\u65ad\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u6240\u5c5e\u7c7b\uff1a<\/strong><\/p>\n<ul>\n<li>wait() \u65b9\u6cd5\u5c5e\u4e8e Object \u7c7b\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u53ef\u4ee5\u7528\u4e8e\u4efb\u4f55 Java \u5bf9\u8c61\u3002<\/li>\n<li>sleep() \u65b9\u6cd5\u5c5e\u4e8e Thread \u7c7b\uff0c\u9700\u8981\u5728 Thread \u5bf9\u8c61\u4e0a\u8c03\u7528\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fJava \u4e2d wt() \u548c sleep() \u65b9\u6cd5\uff1a\u5f02\u540c\u70b9\u8be6\u89e3\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>Java \u4e2d wt() \u548c sleep() \u65b9\u6cd5\u7684\u5f02\u540c \u5728 Java \u4e2d\uff0cwait() \u548c sleep() \u90fd\u662f\u7528\u4e8e\u63a7\u5236\u7ebf\u7a0b\u6267\u884c\u7684\u5e38\u7528\u65b9\u6cd5\uff0c\u4f46\u5b83\u4eec\u4e4b\u95f4\u5b58\u5728\u7740\u4e00\u4e9b\u91cd\u8981\u7684\uff1a \u76f8\u540c\u70b9\uff1a \u5b83\u4eec\u90fd\u53ef\u4ee5\u5728\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\u8ba9\u7ebf\u7a0b\u963b\u585e\u3002 \u5b83\u4eec\u90fd\u53ef\u4ee5\u54cd\u5e94 interrupt \u4e2d\u65ad\uff0c\u5e76\u5728\u7b49\u5f85\u8fc7\u7a0b\u4e2d\u629b\u51fa InterruptedException \u5f02\u5e38\u3002 \u4e0d\u540c\u70b9\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u83b7\u53d6\u548c\u91ca\u653e\u9501\uff1a wait() \u65b9\u6cd5\u53ea\u80fd\u5728 synchronized \u4fdd\u62a4\u7684\u4ee3\u7801\u4e2d\u4f7f\u7528\uff0c\u56e0\u4e3a wait() \u64cd\u4f5c\u9700\u8981\u6301\u6709\u5bf9\u8c61\u7684\u9501\u3002\u800c sleep() \u65b9\u6cd5\u5219\u6ca1\u6709\u8fd9\u4e2a\u8981\u6c42\u3002 \u6267\u884c wait() \u65b9\u6cd5\u65f6\uff0c\u7ebf\u7a0b\u4f1a\u4e3b\u52a8\u91ca\u653e\u5bf9\u8c61\u7684\u9501\uff0c\u800c\u6267\u884c sleep() \u65b9\u6cd5\u65f6\u5e76\u4e0d\u4f1a\u91ca\u653e\u9501\u3002 \u8bbe\u7f6e\u65f6\u95f4\uff1a sleep() \u65b9\u6cd5\u8981\u6c42\u5fc5\u987b\u6307\u5b9a\u4e00\u4e2a\u65f6\u95f4\u503c\uff0c\u5230\u65f6\u540e\u81ea\u52a8\u6062\u590d\u6267\u884c\u3002\u800c wait() \u65b9\u6cd5\u53ef\u4ee5\u4e0d\u6307\u5b9a\u65f6\u95f4\u503c\uff0c\u6b64\u65f6\u7ebf\u7a0b\u5c06\u6c38\u4e45\u7b49\u5f85\uff0c\u76f4\u5230\u6536\u5230\u901a\u77e5\u6216\u4e2d\u65ad\u3002 \u6240\u5c5e\u7c7b\uff1a wait() \u65b9\u6cd5\u5c5e\u4e8e Object \u7c7b\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u53ef\u4ee5\u7528\u4e8e\u4efb\u4f55 Java \u5bf9\u8c61\u3002 sleep() \u65b9\u6cd5\u5c5e\u4e8e Thread \u7c7b\uff0c\u9700\u8981\u5728 Thread \u5bf9\u8c61\u4e0a\u8c03\u7528\u3002 \u4ee5\u4e0a\u5c31\u662fJava \u4e2d [&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-35173","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35173","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=35173"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35173\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=35173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=35173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=35173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}