{"id":35092,"date":"2024-11-26T11:16:20","date_gmt":"2024-11-26T03:16:20","guid":{"rendered":"https:\/\/fwq.ai\/blog\/35092\/"},"modified":"2024-11-26T11:16:20","modified_gmt":"2024-11-26T03:16:20","slug":"java-%e4%b8%ad-wait-%e5%92%8c-sleep-%e7%9a%84%e5%8c%ba%e5%88%ab%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/35092\/","title":{"rendered":"Java \u4e2d wait() \u548c sleep() \u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173060680270915.jpg\" class=\"aligncenter\" title=\"Java \u4e2d wait() \u548c sleep() \u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" alt=\"Java \u4e2d wait() \u548c sleep() \u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u4e2d wt() \u548c sleep() \u7684\u5dee\u5f02<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0cwait() \u548c sleep() \u65b9\u6cd5\u90fd\u7528\u4e8e\u4f7f\u7ebf\u7a0b\u6682\u505c\u6267\u884c\uff0c\u4f46\u4e24\u8005\u4e4b\u95f4\u5b58\u5728\u4e00\u4e9b\u5173\u952e\u5dee\u5f02\u3002<\/p>\n<p><strong>\u76f8\u540c\u70b9<\/strong><\/p>\n<ul>\n<li>\u90fd\u53ef\u4ee5\u6682\u505c\u7ebf\u7a0b<\/li>\n<li>\u90fd\u53ef\u4ee5\u54cd\u5e94\u4e2d\u65ad<\/li>\n<\/ul>\n<p><strong>\u4e0d\u540c\u70b9<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>1. \u83b7\u53d6\u9501<\/strong><\/p>\n<ul>\n<li>wait() \u53ea\u80fd\u5728\u540c\u6b65\u4ee3\u7801\u5757\u5185\u8c03\u7528\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u9700\u8981\u83b7\u53d6\u5bf9\u8c61\u9501\u3002<\/li>\n<li>sleep() \u4e0d\u9700\u8981\u83b7\u53d6\u5bf9\u8c61\u9501\u3002<\/li>\n<\/ul>\n<p><strong>2. \u91ca\u653e\u9501<\/strong><\/p>\n<ul>\n<li>\u5f53 wait() \u88ab\u8c03\u7528\u65f6\uff0c\u5b83\u4f1a\u91ca\u653e\u5bf9\u8c61\u7684\u9501\u3002<\/li>\n<li>sleep() \u4e0d\u91ca\u653e\u5bf9\u8c61\u7684\u9501\u3002<\/li>\n<\/ul>\n<p><strong>3. \u65f6\u95f4\u8bbe\u7f6e<\/strong><\/p>\n<ul>\n<li>sleep() \u5141\u8bb8\u6307\u5b9a\u7761\u7720\u65f6\u95f4\uff0c\u5e76\u5728\u8be5\u65f6\u95f4\u6bb5\u540e\u81ea\u52a8\u6062\u590d\u3002<\/li>\n<li>wait() \u9ed8\u8ba4\u65e0\u9650\u671f\u7b49\u5f85\uff0c\u76f4\u5230\u88ab\u4e2d\u65ad\u6216\u88ab\u5524\u9192\u3002<\/li>\n<\/ul>\n<p><strong>4. \u6240\u5c5e\u7c7b<\/strong><\/p>\n<ul>\n<li>wait() \u662f Object \u7c7b\u7684\u6210\u5458\u65b9\u6cd5\u3002<\/li>\n<li>sleep() \u662f Thread \u7c7b\u7684\u6210\u5458\u65b9\u6cd5\u3002<\/li>\n<\/ul>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>wait() \u7528\u4e8e\u5728\u540c\u6b65\u4e0a\u4e0b\u6587\u4e2d\u6682\u505c\u7ebf\u7a0b\uff0c\u5e76\u91ca\u653e\u5bf9\u8c61\u7684\u9501\u3002sleep() \u7528\u4e8e\u5728\u4efb\u4f55\u4e0a\u4e0b\u6587\u4e2d\u6682\u505c\u7ebf\u7a0b\uff0c\u4f46\u4e0d\u91ca\u653e\u5bf9\u8c61\u7684\u9501\u3002\u9009\u62e9\u4f7f\u7528\u54ea\u79cd\u65b9\u6cd5\u53d6\u51b3\u4e8e\u7279\u5b9a\u7684\u540c\u6b65\u9700\u6c42\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJava \u4e2d wt() \u548c sleep() \u7684\u662f\u4ec0\u4e48\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>Java \u4e2d wt() \u548c sleep() \u7684\u5dee\u5f02 \u5728 Java \u4e2d\uff0cwait() \u548c sleep() \u65b9\u6cd5\u90fd\u7528\u4e8e\u4f7f\u7ebf\u7a0b\u6682\u505c\u6267\u884c\uff0c\u4f46\u4e24\u8005\u4e4b\u95f4\u5b58\u5728\u4e00\u4e9b\u5173\u952e\u5dee\u5f02\u3002 \u76f8\u540c\u70b9 \u90fd\u53ef\u4ee5\u6682\u505c\u7ebf\u7a0b \u90fd\u53ef\u4ee5\u54cd\u5e94\u4e2d\u65ad \u4e0d\u540c\u70b9 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b 1. \u83b7\u53d6\u9501 wait() \u53ea\u80fd\u5728\u540c\u6b65\u4ee3\u7801\u5757\u5185\u8c03\u7528\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u9700\u8981\u83b7\u53d6\u5bf9\u8c61\u9501\u3002 sleep() \u4e0d\u9700\u8981\u83b7\u53d6\u5bf9\u8c61\u9501\u3002 2. \u91ca\u653e\u9501 \u5f53 wait() \u88ab\u8c03\u7528\u65f6\uff0c\u5b83\u4f1a\u91ca\u653e\u5bf9\u8c61\u7684\u9501\u3002 sleep() \u4e0d\u91ca\u653e\u5bf9\u8c61\u7684\u9501\u3002 3. \u65f6\u95f4\u8bbe\u7f6e sleep() \u5141\u8bb8\u6307\u5b9a\u7761\u7720\u65f6\u95f4\uff0c\u5e76\u5728\u8be5\u65f6\u95f4\u6bb5\u540e\u81ea\u52a8\u6062\u590d\u3002 wait() \u9ed8\u8ba4\u65e0\u9650\u671f\u7b49\u5f85\uff0c\u76f4\u5230\u88ab\u4e2d\u65ad\u6216\u88ab\u5524\u9192\u3002 4. \u6240\u5c5e\u7c7b wait() \u662f Object \u7c7b\u7684\u6210\u5458\u65b9\u6cd5\u3002 sleep() \u662f Thread \u7c7b\u7684\u6210\u5458\u65b9\u6cd5\u3002 \u7ed3\u8bba wait() \u7528\u4e8e\u5728\u540c\u6b65\u4e0a\u4e0b\u6587\u4e2d\u6682\u505c\u7ebf\u7a0b\uff0c\u5e76\u91ca\u653e\u5bf9\u8c61\u7684\u9501\u3002sleep() \u7528\u4e8e\u5728\u4efb\u4f55\u4e0a\u4e0b\u6587\u4e2d\u6682\u505c\u7ebf\u7a0b\uff0c\u4f46\u4e0d\u91ca\u653e\u5bf9\u8c61\u7684\u9501\u3002\u9009\u62e9\u4f7f\u7528\u54ea\u79cd\u65b9\u6cd5\u53d6\u51b3\u4e8e\u7279\u5b9a\u7684\u540c\u6b65\u9700\u6c42\u3002 \u4ee5\u4e0a\u5c31\u662fJava \u4e2d wt() \u548c sleep() [&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-35092","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35092","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=35092"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35092\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=35092"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=35092"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=35092"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}