{"id":35701,"date":"2024-11-26T14:42:15","date_gmt":"2024-11-26T06:42:15","guid":{"rendered":"https:\/\/fwq.ai\/blog\/35701\/"},"modified":"2024-11-26T14:42:15","modified_gmt":"2024-11-26T06:42:15","slug":"%e7%94%9f%e4%ba%a7%e8%80%85%e6%b6%88%e8%b4%b9%e8%80%85%e9%97%ae%e9%a2%98%ef%bc%9a%e5%a6%82%e4%bd%95%e8%ae%a9%e5%a4%9a%e4%b8%aa%e6%b6%88%e8%b4%b9%e8%80%85%e5%90%8c%e6%97%b6%e5%8f%82%e4%b8%8e%e6%b6%88","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/35701\/","title":{"rendered":"\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u95ee\u9898\uff1a\u5982\u4f55\u8ba9\u591a\u4e2a\u6d88\u8d39\u8005\u540c\u65f6\u53c2\u4e0e\u6d88\u8d39\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173070275262961.jpg\" class=\"aligncenter\" title=\"\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u95ee\u9898\uff1a\u5982\u4f55\u8ba9\u591a\u4e2a\u6d88\u8d39\u8005\u540c\u65f6\u53c2\u4e0e\u6d88\u8d39\uff1f\u63d2\u56fe\" alt=\"\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u95ee\u9898\uff1a\u5982\u4f55\u8ba9\u591a\u4e2a\u6d88\u8d39\u8005\u540c\u65f6\u53c2\u4e0e\u6d88\u8d39\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u751f\u4ea7\u8005\u4e0e\u6d88\u8d39\u8005\u95ee\u9898\uff1a\u5355\u4e2a\u751f\u4ea7\u8005\uff0c\u591a\u4e2a\u6d88\u8d39\u8005\uff0c\u4f46\u4ec5\u6709\u5355\u4e00\u6d88\u8d39\u8005\u53c2\u4e0e\u6d88\u8d39<\/strong><\/p>\n<p>\u5728\u751f\u4ea7\u8005\u4e0e\u6d88\u8d39\u8005\u95ee\u9898\u4e2d\uff0c\u60a8\u8fd8\u5f15\u5165\u4e86\u591a\u4e2a\u6d88\u8d39\u8005\u7ebf\u7a0b\u3002\u7136\u800c\uff0c\u60a8\u9047\u5230\u7684\u95ee\u9898\u662f\uff0c\u5c3d\u7ba1\u6709\u591a\u4e2a\u6d88\u8d39\u8005\uff0c\u4f46\u53ea\u6709\u4e00\u4e2a\u6d88\u8d39\u8005\u53c2\u4e0e\u6d88\u8d39\u3002<\/p>\n<p>\u95ee\u9898\u51fa\u5728 wt \u548c notifyall \u65b9\u6cd5\u4e0a\u3002wait \u65b9\u6cd5\u53ea\u80fd\u7531\u6301\u6709\u76ee\u6807\u5bf9\u8c61\u9501\u7684\u7ebf\u7a0b\u8c03\u7528\uff0c\u5e76\u4e14 notifyall \u53ea\u4f1a\u5524\u9192\u7531\u8be5\u9501\u8c03\u7528 wait \u7684\u7ebf\u7a0b\u3002<\/p>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5f53\u6d88\u8d39\u8005\u7ebf\u7a0b\u83b7\u53d6\u5217\u8868\u9501\u5e76\u8c03\u7528 wait \u65f6\uff0c\u751f\u4ea7\u8005\u7ebf\u7a0b\u53ef\u4ee5\u83b7\u53d6\u8be5\u9501\u5e76\u751f\u4ea7\u65b0\u5143\u7d20\u3002\u7136\u540e\uff0c\u751f\u4ea7\u8005\u8c03\u7528 notifyall\uff0c\u5b83\u53ea\u4f1a\u5524\u9192\u6301\u6709\u5217\u8868\u9501\u7684\u7ebf\u7a0b\uff08\u5373\u6d88\u8d39\u8005 1\uff09\u3002<\/p>\n<p>\u5f53\u6d88\u8d39\u8005 1 \u6d88\u8d39\u8be5\u5143\u7d20\u5e76\u91ca\u653e\u9501\u65f6\uff0c\u6d88\u8d39\u8005 2 \u5c31\u6ca1\u6709\u673a\u4f1a\u83b7\u53d6\u8be5\u9501\u5e76\u8c03\u7528 wait\u3002\u56e0\u6b64\uff0c\u6bcf\u6b21\u751f\u4ea7\u8005\u751f\u4ea7\u65b0\u5143\u7d20\u65f6\uff0c\u53ea\u6709\u6d88\u8d39\u8005 1 \u80fd\u591f\u6d88\u8d39\u5b83\u3002<\/p>\n<p>\u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u60a8\u53ef\u4ee5\u5728 wait \u65b9\u6cd5\u4e2d\u4f7f\u7528 while \u5faa\u73af\uff0c\u76f4\u5230\u5217\u8868\u4e3a\u7a7a\u624d\u91ca\u653e\u9501\u3002\u8fd9\u6837\uff0c\u591a\u4e2a\u6d88\u8d39\u8005\u7ebf\u7a0b\u5c31\u6709\u673a\u4f1a\u5728\u6bcf\u4e2a\u751f\u4ea7\u8005\u5468\u671f\u5185\u83b7\u53d6\u9501\u5e76\u6d88\u8d39\u5143\u7d20\u3002\u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>while (true) {\n    synchronized (list) {\n        if (list.size() == 0) {\n            try {\n                list.wait();\n            } catch (InterruptedException e) {\n                e.printStackTrace();\n            }\n        }\n        Object object = list.remove(0);\n        System.out.println(Thread.currentThread().getName() + \"\u6d88\u8d39 list\" + object);\n        list.notifyAll();\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u95ee\u9898\uff1a\u5982\u4f55\u8ba9\u591a\u4e2a\u6d88\u8d39\u8005\u540c\u65f6\u53c2\u4e0e\u6d88\u8d39\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>\u751f\u4ea7\u8005\u4e0e\u6d88\u8d39\u8005\u95ee\u9898\uff1a\u5355\u4e2a\u751f\u4ea7\u8005\uff0c\u591a\u4e2a\u6d88\u8d39\u8005\uff0c\u4f46\u4ec5\u6709\u5355\u4e00\u6d88\u8d39\u8005\u53c2\u4e0e\u6d88\u8d39 \u5728\u751f\u4ea7\u8005\u4e0e\u6d88\u8d39\u8005\u95ee\u9898\u4e2d\uff0c\u60a8\u8fd8\u5f15\u5165\u4e86\u591a\u4e2a\u6d88\u8d39\u8005\u7ebf\u7a0b\u3002\u7136\u800c\uff0c\u60a8\u9047\u5230\u7684\u95ee\u9898\u662f\uff0c\u5c3d\u7ba1\u6709\u591a\u4e2a\u6d88\u8d39\u8005\uff0c\u4f46\u53ea\u6709\u4e00\u4e2a\u6d88\u8d39\u8005\u53c2\u4e0e\u6d88\u8d39\u3002 \u95ee\u9898\u51fa\u5728 wt \u548c notifyall \u65b9\u6cd5\u4e0a\u3002wait \u65b9\u6cd5\u53ea\u80fd\u7531\u6301\u6709\u76ee\u6807\u5bf9\u8c61\u9501\u7684\u7ebf\u7a0b\u8c03\u7528\uff0c\u5e76\u4e14 notifyall \u53ea\u4f1a\u5524\u9192\u7531\u8be5\u9501\u8c03\u7528 wait \u7684\u7ebf\u7a0b\u3002 \u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5f53\u6d88\u8d39\u8005\u7ebf\u7a0b\u83b7\u53d6\u5217\u8868\u9501\u5e76\u8c03\u7528 wait \u65f6\uff0c\u751f\u4ea7\u8005\u7ebf\u7a0b\u53ef\u4ee5\u83b7\u53d6\u8be5\u9501\u5e76\u751f\u4ea7\u65b0\u5143\u7d20\u3002\u7136\u540e\uff0c\u751f\u4ea7\u8005\u8c03\u7528 notifyall\uff0c\u5b83\u53ea\u4f1a\u5524\u9192\u6301\u6709\u5217\u8868\u9501\u7684\u7ebf\u7a0b\uff08\u5373\u6d88\u8d39\u8005 1\uff09\u3002 \u5f53\u6d88\u8d39\u8005 1 \u6d88\u8d39\u8be5\u5143\u7d20\u5e76\u91ca\u653e\u9501\u65f6\uff0c\u6d88\u8d39\u8005 2 \u5c31\u6ca1\u6709\u673a\u4f1a\u83b7\u53d6\u8be5\u9501\u5e76\u8c03\u7528 wait\u3002\u56e0\u6b64\uff0c\u6bcf\u6b21\u751f\u4ea7\u8005\u751f\u4ea7\u65b0\u5143\u7d20\u65f6\uff0c\u53ea\u6709\u6d88\u8d39\u8005 1 \u80fd\u591f\u6d88\u8d39\u5b83\u3002 \u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u60a8\u53ef\u4ee5\u5728 wait \u65b9\u6cd5\u4e2d\u4f7f\u7528 while \u5faa\u73af\uff0c\u76f4\u5230\u5217\u8868\u4e3a\u7a7a\u624d\u91ca\u653e\u9501\u3002\u8fd9\u6837\uff0c\u591a\u4e2a\u6d88\u8d39\u8005\u7ebf\u7a0b\u5c31\u6709\u673a\u4f1a\u5728\u6bcf\u4e2a\u751f\u4ea7\u8005\u5468\u671f\u5185\u83b7\u53d6\u9501\u5e76\u6d88\u8d39\u5143\u7d20\u3002\u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a while (true) { synchronized (list) { if (list.size() == 0) { try { list.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } Object object = [&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-35701","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35701","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=35701"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35701\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=35701"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=35701"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=35701"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}