{"id":937,"date":"2018-08-06T22:45:42","date_gmt":"2018-08-06T14:45:42","guid":{"rendered":"https:\/\/199604.com\/?p=937"},"modified":"2019-07-13T11:30:30","modified_gmt":"2019-07-13T03:30:30","slug":"%e4%b8%80%e4%b8%aa%e7%ba%bf%e7%a8%8b%e4%be%8b%e5%ad%90","status":"publish","type":"post","link":"https:\/\/199604.com\/937","title":{"rendered":"\u4e00\u4e2a\u7ebf\u7a0b\u4f8b\u5b50"},"content":{"rendered":"<p>emmm&#8230;<\/p>\n<p>\u4ee3\u7801\u5982\u4e0b<\/p>\n<pre class=\"lang:default decode:true\">import java.util.ArrayList;\nimport java.util.List;\n\npublic class Main {\n\n    private static List&lt;Integer&gt; list = new ArrayList&lt;&gt;();\n\n    public static void main(String[] args) {\n        Thread thread1 = new Thread(new TestRunnable(list));\n        thread1.start();\n\n        TestThread thread2 = new TestThread(list);\n        thread2.run();\n\n    }\n\n   static class TestRunnable implements Runnable{\n\n       private  List&lt;Integer&gt; list;\n\n       public TestRunnable(List&lt;Integer&gt; list) {\n           this.list = list;\n       }\n\n       @Override\n        public void run() {\n            Thread.currentThread().setName(\"Runnable\u7ebf\u7a0b\");\n            for(int i=0;i&lt;200;i++){\n                TestThreadAddList testThreadAddList = new TestThreadAddList(i,list);\n                testThreadAddList.run();\n               \/\/ System.out.println(Thread.currentThread().getName()+\"\u7b2c\"+i+\"\u4e2a\");\n               \/\/ System.out.println(Thread.currentThread().getName()+\"list\u5927\u5c0f\"+list.size());\n            }\n\n        }\n    }\n\n    static class TestThread extends Thread{\n        private  List&lt;Integer&gt; list;\n\n        public TestThread(List&lt;Integer&gt; list) {\n            this.list = list;\n        }\n\n        @Override\n        public void run() {\n            Thread.currentThread().setName(\"Thread\u7ebf\u7a0b\");\n            for(int i=0;i&lt;200;i++){\n                TestThreadAddList testThreadAddList = new TestThreadAddList(i,list);\n                testThreadAddList.run();\n               \/\/ System.out.println(Thread.currentThread().getName()+\"list\u5927\u5c0f\"+list.size());\n                \/\/ System.out.println(Thread.currentThread().getName()+\"\u7b2c\"+i+\"\u4e2a\");\n            }\n        }\n    }\n\n    static class TestThreadAddList extends Thread{\n        private  int num;\n        private  List&lt;Integer&gt; list;\n\n        public TestThreadAddList( int num, List&lt;Integer&gt; list) {\n            this.num = num;\n            this.list = list;\n        }\n\n        @Override\n        public void run() {\n            synchronized (TestThreadAddList.class){\n              list.add(num);\n                System.out.println(Thread.currentThread().getName()+\"list\u5927\u5c0f\"+list.size());\n            }\n        }\n    }\n\n}\n<\/pre>\n<hr \/>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/qn.199604.com\/wp-content\/uploads\/2017\/07\/zhifubao.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large\" data-original=\"http:\/\/qn.199604.com\/wp-content\/uploads\/2017\/07\/zhifubao.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" width=\"318\" height=\"406\" \/><\/div><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/qn.199604.com\/wp-content\/uploads\/2017\/07\/weixin.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large\" data-original=\"http:\/\/qn.199604.com\/wp-content\/uploads\/2017\/07\/weixin.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" width=\"268\" height=\"291\" \/><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>emmm&#8230; \u4ee3\u7801\u5982\u4e0b import java.util.ArrayList; import jav [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[130],"tags":[178],"class_list":["post-937","post","type-post","status-publish","format-standard","hentry","category-java","tag-178"],"_links":{"self":[{"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/posts\/937","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/comments?post=937"}],"version-history":[{"count":2,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/posts\/937\/revisions"}],"predecessor-version":[{"id":1210,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/posts\/937\/revisions\/1210"}],"wp:attachment":[{"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/media?parent=937"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/categories?post=937"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/tags?post=937"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}