{"id":35662,"date":"2024-11-26T14:23:19","date_gmt":"2024-11-26T06:23:19","guid":{"rendered":"https:\/\/fwq.ai\/blog\/35662\/"},"modified":"2024-11-26T14:23:19","modified_gmt":"2024-11-26T06:23:19","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%e4%b8%ba%e4%bb%80%e4%b9%88%e5%a4%9a%e4%b8%aa%e6%b6%88%e8%b4%b9%e8%80%85%e5%8f%aa%e6%9c%89%e4%b8%80%e4%b8%aa%e5%8f%82","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/35662\/","title":{"rendered":"\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u95ee\u9898\uff1a\u4e3a\u4ec0\u4e48\u591a\u4e2a\u6d88\u8d39\u8005\u53ea\u6709\u4e00\u4e2a\u53c2\u4e0e\u6d88\u8d39\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173069046599573.jpg\" class=\"aligncenter\" title=\"\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u95ee\u9898\uff1a\u4e3a\u4ec0\u4e48\u591a\u4e2a\u6d88\u8d39\u8005\u53ea\u6709\u4e00\u4e2a\u53c2\u4e0e\u6d88\u8d39\uff1f\u63d2\u56fe\" alt=\"\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u95ee\u9898\uff1a\u4e3a\u4ec0\u4e48\u591a\u4e2a\u6d88\u8d39\u8005\u53ea\u6709\u4e00\u4e2a\u53c2\u4e0e\u6d88\u8d39\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u95ee\u9898\uff1a\u591a\u4e2a\u6d88\u8d39\u8005\u4e2d\u53ea\u6709\u4e00\u4e2a\u53c2\u4e0e\u6d88\u8d39<\/strong><\/p>\n<p>\u5728\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u5f0f\u4e2d\uff0c\u5c3d\u7ba1\u5b58\u5728\u591a\u4e2a\u6d88\u8d39\u8005\u7ebf\u7a0b\uff0c\u4f46\u7a0b\u5e8f\u4e2d\u4ec5\u6709\u4e00\u4e2a\u6d88\u8d39\u8005\u53c2\u4e0e\u6d88\u8d39\uff0c\u8fdd\u80cc\u4e86\u9884\u671f\u3002<\/p>\n<p><strong>\u95ee\u9898\u539f\u56e0<\/strong><\/p>\n<p>\u6b64\u95ee\u9898\u6839\u6e90\u5728\u4e8e wt() \u548c notifyall() \u65b9\u6cd5\u7684\u673a\u5236\u3002\u53ea\u6709\u6301\u624d\u80fd\u8c03\u7528 wait() \u65b9\u6cd5\uff0c\u800c notifyall() \u53ea\u80fd\u5524\u9192\u7531\u8be5\u9501\u8c03\u7528 wait() \u65b9\u6cd5\u800c\u5904\u4e8e\u7b49\u5f85\u72b6\u6001\u7684\u7ebf\u7a0b\u3002<\/p>\n<p><strong>\u7a0b\u5e8f\u6267\u884c\u6d41\u7a0b<\/strong><\/p>\n<ol>\n<li>\u751f\u4ea7\u8005\u7ebf\u7a0b\u83b7\u53d6\u9501\uff0c\u751f\u4ea7\u8d44\u6e90\u5e76\u5524\u9192\u6240\u6709\u7b49\u5f85\u7ebf\u7a0b\u3002<\/li>\n<li>\u591a\u4e2a\u6d88\u8d39\u8005\u7ebf\u7a0b\u7ade\u4e89\u9501\uff0c\u5047\u8bbe\u6d88\u8d39\u8005 1 \u9996\u5148\u83b7\u53d6\u9501\u3002<\/li>\n<li>\u6d88\u8d39\u8005 1 \u6d88\u8d39\u8d44\u6e90\u5e76\u5524\u9192\u6240\u6709\u7b49\u5f85\u7ebf\u7a0b\uff0c\u4f46\u5c1a\u672a\u91ca\u653e\u9501\u3002<\/li>\n<li>\u751f\u4ea7\u8005\u7ebf\u7a0b\u88ab\u5524\u9192\uff0c\u4f46\u7531\u4e8e\u5224\u65ad\u8d44\u6e90\u6570\u91cf\u5927\u4e8e 0\uff0c\u518d\u6b21\u8fdb\u5165\u7b49\u5f85\u72b6\u6001\u3002<\/li>\n<li>\u6d88\u8d39\u8005 1 \u6301\u7eed\u6301\u6709\u9501\uff0c\u6ca1\u6709\u673a\u4f1a\u8ba9\u5176\u4ed6\u6d88\u8d39\u8005\u53c2\u4e0e\u6d88\u8d39\u3002<\/li>\n<\/ol>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u4e3a\u4e86\u8ba9\u6240\u6709\u6d88\u8d39\u8005\u90fd\u6709\u673a\u4f1a\u53c2\u4e0e\u6d88\u8d39\uff0c\u9700\u8981\u4fee\u6539\u7a0b\u5e8f\u903b\u8f91\uff0c\u786e\u4fdd\u5728\u6d88\u8d39\u8005\u7ebf\u7a0b\u91ca\u653e\u9501\u4e4b\u524d\uff0c\u5524\u9192\u6240\u6709\u7b49\u5f85\u7ebf\u7a0b\u3002<\/p>\n<p>\u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>class ConThread extends Thread {\n    private List list;\n\n    public ConThread(List list) {\n        this.list = list;\n    }\n\n    @Override\n    public void run() {\n        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\n                Object object = list.remove(0);\n                System.out.println(Thread.currentThread().getName() + \"\u6d88\u8d39 list\" + object);\n\n                \/\/ \u91ca\u653e\u9501\u540e\u518d\u5524\u9192\u6240\u6709\u7b49\u5f85\u7ebf\u7a0b\n                list.notifyAll();\n            }\n        }\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\u4e3a\u4ec0\u4e48\u591a\u4e2a\u6d88\u8d39\u8005\u53ea\u6709\u4e00\u4e2a\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\u6d88\u8d39\u8005\u95ee\u9898\uff1a\u591a\u4e2a\u6d88\u8d39\u8005\u4e2d\u53ea\u6709\u4e00\u4e2a\u53c2\u4e0e\u6d88\u8d39 \u5728\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u5f0f\u4e2d\uff0c\u5c3d\u7ba1\u5b58\u5728\u591a\u4e2a\u6d88\u8d39\u8005\u7ebf\u7a0b\uff0c\u4f46\u7a0b\u5e8f\u4e2d\u4ec5\u6709\u4e00\u4e2a\u6d88\u8d39\u8005\u53c2\u4e0e\u6d88\u8d39\uff0c\u8fdd\u80cc\u4e86\u9884\u671f\u3002 \u95ee\u9898\u539f\u56e0 \u6b64\u95ee\u9898\u6839\u6e90\u5728\u4e8e wt() \u548c notifyall() \u65b9\u6cd5\u7684\u673a\u5236\u3002\u53ea\u6709\u6301\u624d\u80fd\u8c03\u7528 wait() \u65b9\u6cd5\uff0c\u800c notifyall() \u53ea\u80fd\u5524\u9192\u7531\u8be5\u9501\u8c03\u7528 wait() \u65b9\u6cd5\u800c\u5904\u4e8e\u7b49\u5f85\u72b6\u6001\u7684\u7ebf\u7a0b\u3002 \u7a0b\u5e8f\u6267\u884c\u6d41\u7a0b \u751f\u4ea7\u8005\u7ebf\u7a0b\u83b7\u53d6\u9501\uff0c\u751f\u4ea7\u8d44\u6e90\u5e76\u5524\u9192\u6240\u6709\u7b49\u5f85\u7ebf\u7a0b\u3002 \u591a\u4e2a\u6d88\u8d39\u8005\u7ebf\u7a0b\u7ade\u4e89\u9501\uff0c\u5047\u8bbe\u6d88\u8d39\u8005 1 \u9996\u5148\u83b7\u53d6\u9501\u3002 \u6d88\u8d39\u8005 1 \u6d88\u8d39\u8d44\u6e90\u5e76\u5524\u9192\u6240\u6709\u7b49\u5f85\u7ebf\u7a0b\uff0c\u4f46\u5c1a\u672a\u91ca\u653e\u9501\u3002 \u751f\u4ea7\u8005\u7ebf\u7a0b\u88ab\u5524\u9192\uff0c\u4f46\u7531\u4e8e\u5224\u65ad\u8d44\u6e90\u6570\u91cf\u5927\u4e8e 0\uff0c\u518d\u6b21\u8fdb\u5165\u7b49\u5f85\u72b6\u6001\u3002 \u6d88\u8d39\u8005 1 \u6301\u7eed\u6301\u6709\u9501\uff0c\u6ca1\u6709\u673a\u4f1a\u8ba9\u5176\u4ed6\u6d88\u8d39\u8005\u53c2\u4e0e\u6d88\u8d39\u3002 \u89e3\u51b3\u65b9\u6848 \u4e3a\u4e86\u8ba9\u6240\u6709\u6d88\u8d39\u8005\u90fd\u6709\u673a\u4f1a\u53c2\u4e0e\u6d88\u8d39\uff0c\u9700\u8981\u4fee\u6539\u7a0b\u5e8f\u903b\u8f91\uff0c\u786e\u4fdd\u5728\u6d88\u8d39\u8005\u7ebf\u7a0b\u91ca\u653e\u9501\u4e4b\u524d\uff0c\u5524\u9192\u6240\u6709\u7b49\u5f85\u7ebf\u7a0b\u3002 \u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a class ConThread extends Thread { private List list; public ConThread(List list) { this.list = list; } @Override public void run() { while (true) { synchronized [&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-35662","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35662","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=35662"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35662\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=35662"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=35662"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=35662"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}