
{"id":2216,"date":"2020-08-30T12:54:48","date_gmt":"2020-08-30T04:54:48","guid":{"rendered":"http:\/\/127.0.0.2\/?p=2216"},"modified":"2020-08-30T12:54:48","modified_gmt":"2020-08-30T04:54:48","slug":"2020java%e6%95%99%e7%a8%8b%ef%bc%9a%e5%8c%bf%e5%90%8d%e5%86%85%e9%83%a8%e7%b1%bb%e5%ae%8c%e6%88%90%e7%94%9f%e4%ba%a7%e8%80%85%e5%92%8c%e6%b6%88%e8%b4%b9%e8%80%85","status":"publish","type":"post","link":"https:\/\/www.9713job.com\/?p=2216","title":{"rendered":"2020java\u6559\u7a0b\uff1a\u533f\u540d\u5185\u90e8\u7c7b\u5b8c\u6210\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005"},"content":{"rendered":"<h3>\u533f\u540d\u5185\u90e8\u7c7b\u5b8c\u6210\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005<\/h3>\n<pre>public class demos{\r\n    public static void main(String[] args) {\r\n        MyStack ms=new MyStack();\r\n        Thread t1=new Thread(){\r\n            public void run() {\r\n                for(char c='A';c&lt;='Z';c++){\r\n                    ms.push(c+\"\");\r\n                }\r\n            }\r\n        };\r\n        Thread t2=new Thread(){\r\n            public void run() {\r\n                for(int i=0;i&lt;26;i++){\r\n                    ms.poll();\r\n                }\r\n            }\r\n        };\r\n        t1.start();\r\n        t2.start();\r\n    }\r\n}\r\nclass MyStack{\r\n    private String[] values={\"\",\"\",\"\",\"\",\"\"};\r\n    private int size=0;\r\n    public synchronized void push(String s){\r\n        this.notifyAll();\r\n        while(values.length==size){\r\n            try {\r\n                this.wait();\r\n            } catch (InterruptedException e) {\r\n                e.printStackTrace();\r\n            }\r\n        }\r\n        System.out.println(s+\"\u5165\u6808\");\r\n        values[size]=s;\r\n        size++;\r\n    }\r\n    public synchronized void poll(){\r\n        this.notifyAll();\r\n        while(size==0){\r\n            try {\r\n                this.wait();\r\n            } catch (InterruptedException e) {\r\n                e.printStackTrace();\r\n            }\r\n        }\r\n        System.out.println(values[size-1]+\"\u51fa\u6808\");\r\n        values[size-1]=\"\";\r\n        size--;\r\n    }\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u533f\u540d\u5185\u90e8\u7c7b\u5b8c\u6210\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005 public class demos{ public static void m [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-2216","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2216","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2216"}],"version-history":[{"count":1,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2216\/revisions"}],"predecessor-version":[{"id":2217,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2216\/revisions\/2217"}],"wp:attachment":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2216"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}