{"id":147,"date":"2022-03-29T17:18:20","date_gmt":"2022-03-29T09:18:20","guid":{"rendered":"https:\/\/wordpress.rslly.top\/?p=147"},"modified":"2022-03-29T17:18:20","modified_gmt":"2022-03-29T09:18:20","slug":"%e8%81%8a%e8%81%8ajava%e5%b9%b6%e5%8f%91%e9%82%a3%e4%ba%9b%e4%ba%8b%e6%83%85","status":"publish","type":"post","link":"https:\/\/wordpress.rslly.top\/index.php\/2022\/03\/29\/%e8%81%8a%e8%81%8ajava%e5%b9%b6%e5%8f%91%e9%82%a3%e4%ba%9b%e4%ba%8b%e6%83%85\/","title":{"rendered":"\u804a\u804ajava\u5e76\u53d1\u90a3\u4e9b\u4e8b\u60c5"},"content":{"rendered":"\n<p>\u968f\u98ce<\/p>\n\n\n\n<p>\u968f\u7740\u6469\u5c14\u5b9a\u5f8b\u65e5\u6e10\u5931\u6548\uff0c\u591a\u6838\u5fc3\u7f16\u7a0b\u5df2\u7ecf\u662f\u4e0d\u5f97\u4e0d\u9762\u5bf9\u7684\u73b0\u5b9e\u3002\u800cjava\u4ece\u4e00\u5f00\u59cb\u5c31\u8bbe\u8ba1\u6210\u4e86\u4e00\u79cd\u652f\u6301\u591a\u7ebf\u7a0b\u7684\u8bed\u8a00\u3002\u90a3\u4e48\u6211\u4eec\u5982\u4f55\u4f7f\u7528java\u6765\u8fdb\u884c\u591a\u7ebf\u7a0b\u7a0b\u5e8f\u7684\u7f16\u5199\u5462\uff1f\u5f88\u7b80\u5355\uff0c\u4e00\u822c\u6765\u8bf4\uff0c\u5728java\u5f00\u542f\u4e00\u4e2a\u591a\u7ebf\u7a0b\uff0c\u6211\u4eec\u6709\u4e09\u79cd\u65b9\u6cd5\uff0c\u8fd9\u51e0\u79cd\u65b9\u6cd5\u4f7f\u7528\u573a\u5408\u4e0d\u4e00\u6837\uff0c\u5e76\u6ca1\u6709\u5b70\u4f18\u5b70\u52a3\u3002<\/p>\n\n\n\n<p>1.\u7ee7\u627fThread\u7c7b\uff0c\u8fd9\u79cd\u65b9\u6cd5\u5f88\u7b80\u5355\uff0c\u4f46\u662fjava\u662f\u5355\u7ee7\u627f\u7684\uff0c\u8fd9\u963b\u788d\u4e86\u4f60\u4e1a\u52a1\u7684\u7ee7\u627f\u6269\u5c55\uff0c\u56e0\u6b64\u5e76\u4e0d\u9002\u7528\u4e8e\u9700\u8981\u7ee7\u627f\u6269\u5c55\u7684\u573a\u5408\u3002<\/p>\n\n\n\n<p>2.\u5b9e\u73b0Runnable\u63a5\u53e3\uff0c\u8fd9\u79cd\u65b9\u6cd5\u6bd4\u8f83\u7075\u6d3b\u800c\u4e14\u7b80\u5355\u3002\u540e\u9762\u6587\u7ae0\u4e5f\u4e3b\u8981\u4f7f\u7528\u8fd9\u79cd\u65b9\u6cd5\u3002\u8fd9\u79cd\u65b9\u6cd5\u53ea\u9700\u8981\u5b9e\u73b0run\u65b9\u6cd5\u5c31\u53ef\u4ee5\u8f7b\u677e\u521b\u5efa\u4e00\u4e2a\u7ebf\u7a0b\u3002<\/p>\n\n\n\n<p>3.\u5b9e\u73b0Callable\u63a5\u53e3\uff0c\u8fd9\u79cd\u65b9\u6cd5\u529f\u80fd\u6700\u4e3a\u5f3a\u5927\uff0c\u53ef\u4ee5\u5728\u4efb\u52a1\u7ed3\u675f\u540e\u8fd4\u56de\u503c\u3002call\u65b9\u6cd5\u8fd8\u80fd\u591f\u629b\u51fa\u5f02\u5e38\u3002\u800crun\u65b9\u6cd5\u5e76\u4e0d\u80fd\u8fd4\u56de\u503c\u3002<\/p>\n\n\n\n<p>\u4e0b\u9762\u662f\u521b\u5efa\u7ebf\u7a0b\u7684\u7b80\u5355\u4f8b\u5b50\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">package com.company;\n\n\n\nclass MyThread2 implements Runnable{\n    private static int count = 0;\/\/ \u8ba1\u6570\u5668\n\n    @Override\n    public void run() {\n       synchronized (this) {\n           ++count;\n\n           try {\n               Thread.sleep(1000);\n           } catch (InterruptedException e) {\n               e.printStackTrace();\n           }\n           System.out.println(count);\n       }\n    }\n}\npublic class test {\n    public static void main(String args[]){\n         MyThread2 myThread2=new MyThread2();\n         Thread t1=new Thread(myThread2,\"t1\");\n         Thread t2=new Thread(myThread2,\"t2\");\n         Thread t3=new Thread(myThread2,\"t3\");\n         t1.start();\n         t2.start();\n         t3.start();\n    }\n}\n<\/pre>\n\n\n\n<p>\u53ef\u4ee5\u770b\u51fa\u521b\u5efa\u4e00\u4e2a\u7ebf\u7a0b\u8fd8\u662f\u76f8\u5f53\u7684\u7b80\u5355\u7684\uff0c\u4f46\u4ee4\u4eba\u5934\u75bc\u7684\u5176\u5b9e\u662f\u7ebf\u7a0b\u540c\u6b65\u95ee\u9898\u3002\u4e0a\u8ff0\u4ee3\u7801\u4e2d++count\u5e76\u4e0d\u662f\u4e00\u4e2aatomic\u64cd\u4f5c\u3002\u5b9e\u9645\u4e0a\u5305\u542b\u4e86\u67e5\u8be2\uff0c+1\u548c\u8d4b\u503c\u64cd\u4f5c\uff0c\u8fd9\u6837\u7684\u7ed3\u679c\u5c31\u662f\u5728\u5e76\u53d1\u4e2d\u4f1a\u4ea7\u751f\u6240\u8c13\u7684\u7ebf\u7a0b\u540c\u6b65\u95ee\u9898\uff0c\u8bfb\u8005\u53ef\u4ee5\u8bd5\u7740\u628a\u540c\u6b65\u5b57\u6bb5\u5220\u9664\u3002\u8fd9\u5c06\u4f1a\u5bfc\u81f4\u7ed3\u679c\u4e3a333\uff0c\u8fd9\u4e0e\u8bbe\u8ba1\u7684\u521d\u8877\u5c31\u53d1\u751f\u4e86\u8fdd\u80cc\u3002\u4e3a\u4ec0\u4e48\u4f1a\u8fd9\u6837\u5462\uff1f\u539f\u56e0\u5f88\u7b80\u5355\uff0csleep\u7684\u65f6\u5019\u7ebf\u7a0b\u5c06\u4f1a\u88ab\u6302\u8d77\uff0c\u8fd9\u6837\u5176\u5b83\u7ebf\u7a0b\u5c31\u4f1a\u76f8\u7ee7\u8fdb\u884c++count\u64cd\u4f5c\u7136\u540e\u4e5f\u88ab\u6302\u8d77\u3002\u6700\u540e\u8f93\u51fa\u7684\u5f53\u7136\u662f\u6700\u7ec8\u7684\u6570\u503c3\u3002\u56e0\u6b64\u5982\u679c\u6211\u4eec\u9700\u8981\u4f7f\u5176\u7ebf\u7a0b\u540c\u6b65\u7684\u8bdd\uff0c\u6211\u4eec\u9700\u8981\u52a0\u4e0a\u4e92\u65a5\u9501\uff0c\u901a\u8fc7\u9501\u7684\u7ade\u4e89\u786e\u4fdd\u5176\u540c\u6b65\u3002\u4f46\u8fd9\u6837\u7684\u4ee3\u4ef7\u662f\u591a\u7ebf\u7a0b\u5b9e\u9645\u4e0a\u9000\u5316\u4e86\u3002\u8fd9\u6837\u5c31\u5bfc\u81f4\u4e86\u6027\u80fd\u5b9e\u9645\u4e0a\u6ca1\u6709\u63d0\u9ad8\uff0c\u53cd\u800c\u7531\u4e8e\u4e0a\u4e0b\u6587\u5207\u6362\u7b49\u4e0b\u964d\u4e86\u3002<\/p>\n\n\n\n<p>\u53ef\u80fd\u8bfb\u8005\u4f1a\u89c9\u5f97\u8fd9\u6837\u4e00\u6bb5\u5c0f\u4ee3\u7801\u6ca1\u6709\u4ec0\u4e48\u5b9e\u9645\u7528\u9014\uff0c\u5176\u5b9e\u8fd9\u79cd\u60f3\u6cd5\u662f\u9519\u8bef\u7684\uff0cjava springboot controller\u5b9e\u9645\u4e0a\u662f\u5355\u4f8b\u591a\u7ebf\u7a0b\u7684\uff0c\u56e0\u6b64\u5982\u679c\u6211\u4eec\u5728@controller\u4e0b\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\u5c06\u4f1a\u5bfc\u81f4\u8ddf\u4e0a\u9762\u4e00\u6837\u7684\u9519\u8bef\u3002\u5982\u679c\u6211\u4eec\u505a\u7684\u662f\u8d2d\u7269\u7cfb\u7edf\uff0c\u90a3\u4e48\u5f88\u9057\u61be\uff0c\u4f60\u8fd9\u4e2a\u7cfb\u7edf\u5c06\u4f1a\u4ea7\u751f\u8d85\u5356\u95ee\u9898\u3002\u5f53\u6709\u4eba\u53ef\u80fd\u4f1a\u8bf4\uff0c\u6211\u4eec\u5462\u5e73\u65f6crud\u4e5f\u6ca1\u611f\u89c9\u8981\u52a0\u9501\uff0c\u5176\u5b9e\u6570\u636e\u5e93\u7684\u4e8b\u52a1\u672c\u6765\u5c31\u662fatomic\u7684\uff0c\u6240\u4ee5\u5e76\u4e0d\u9700\u8981\u52a0\u9501\u3002\u56e0\u6b64\u6211\u4eec\u6280\u672f\u4eba\u8981\u611f\u8c22\u524d\u4eba\u7684\u52aa\u529b\uff0c\u624d\u4f7f\u5f97\u73b0\u5728\u505a\u4e00\u4e2aweb\u5e94\u7528\u5982\u6b64\u7b80\u5355\uff0c\u4f46\u662f\u7b80\u5355\u7684\u80cc\u540e\u5374\u662ftomcat\u548cspring\u5168\u5bb6\u6876\u8fd9\u6837\u7684\u5927\u9ed1\u7bb1\u3002\u5982\u679c\u6211\u4eec\u4e0d\u52aa\u529b\u7814\u7a76\u9ed1\u7bb1\u7684\u672c\u8eab\uff0c\u90a3\u4e48\u6700\u7ec8\u6211\u4eec\u5c31\u53ea\u80fd\u662f\u4e00\u4e2acrud\u7a0b\u5e8f\u733f\u3002<\/p>\n\n\n\n<p>\u6700\u540e\u5356\u4e2a\u5e7f\u544a\uff0c\u521b\u4e07\u8054\u65b0\u4e00\u4ee3\u7269\u8054\u7f51\u5e73\u53f0\u6b63\u5728\u706b\u70ed\u5efa\u8bbe\u4e2d\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u5927\u91cf\u7684\u4f18\u79c0\u7279\u6027\u3002\u66f4\u5b89\u5168\uff0c\u63a5\u53e3\u66f4\u52a0\u89c4\u8303\uff0c\u6781\u5927\u63d0\u9ad8\u4e86\u201c\u67d4\u6027\u201d\u7a0b\u5ea6\u3002\u5e73\u53f0\u8ddf\u9879\u76ee\u7ed1\u5b9a\u7684\u65f6\u4ee3\u4e5f\u8bb8\u5c06\u8981\u5f7b\u5e95\u544a\u522b\uff0c\u6211\u4eec\u6b22\u8fce\u5404\u4f4d\u5f00\u6e90\u4eba\u58eb\u7684\u52a0\u5165\uff0c\u4f60\u4eec\u7684\u52a0\u5165\u662f\u6211\u4eec\u7ec4\u7ec7\u7684\u798f\u6c14\u3002\u8ba9\u6211\u4eec\u5171\u540c\u8fce\u63a5aiot\u548c\u6570\u5b57\u5b6a\u751f\u7684\u7f8e\u597d\u672a\u6765\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"344\" height=\"344\" src=\"https:\/\/wordpress.rslly.top\/wp-content\/uploads\/2020\/10\/\u5fae\u4fe1\u56fe\u7247_20201007185559.jpg\" alt=\"\" class=\"wp-image-37\" srcset=\"https:\/\/wordpress.rslly.top\/wp-content\/uploads\/2020\/10\/\u5fae\u4fe1\u56fe\u7247_20201007185559.jpg 344w, https:\/\/wordpress.rslly.top\/wp-content\/uploads\/2020\/10\/\u5fae\u4fe1\u56fe\u7247_20201007185559-300x300.jpg 300w, https:\/\/wordpress.rslly.top\/wp-content\/uploads\/2020\/10\/\u5fae\u4fe1\u56fe\u7247_20201007185559-150x150.jpg 150w\" sizes=\"auto, (max-width: 344px) 100vw, 344px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u968f\u98ce \u968f\u7740\u6469\u5c14\u5b9a\u5f8b\u65e5\u6e10\u5931\u6548\uff0c\u591a\u6838\u5fc3\u7f16\u7a0b\u5df2\u7ecf\u662f\u4e0d\u5f97\u4e0d\u9762\u5bf9\u7684\u73b0\u5b9e\u3002\u800cjava\u4ece\u4e00\u5f00\u59cb\u5c31\u8bbe\u8ba1\u6210\u4e86\u4e00\u79cd\u652f\u6301\u591a\u7ebf\u7a0b\u7684\u8bed\u8a00 &hellip; <a href=\"https:\/\/wordpress.rslly.top\/index.php\/2022\/03\/29\/%e8%81%8a%e8%81%8ajava%e5%b9%b6%e5%8f%91%e9%82%a3%e4%ba%9b%e4%ba%8b%e6%83%85\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u804a\u804ajava\u5e76\u53d1\u90a3\u4e9b\u4e8b\u60c5<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"spay_email":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-147","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/wordpress.rslly.top\/index.php\/wp-json\/wp\/v2\/posts\/147","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.rslly.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.rslly.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.rslly.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.rslly.top\/index.php\/wp-json\/wp\/v2\/comments?post=147"}],"version-history":[{"count":5,"href":"https:\/\/wordpress.rslly.top\/index.php\/wp-json\/wp\/v2\/posts\/147\/revisions"}],"predecessor-version":[{"id":153,"href":"https:\/\/wordpress.rslly.top\/index.php\/wp-json\/wp\/v2\/posts\/147\/revisions\/153"}],"wp:attachment":[{"href":"https:\/\/wordpress.rslly.top\/index.php\/wp-json\/wp\/v2\/media?parent=147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.rslly.top\/index.php\/wp-json\/wp\/v2\/categories?post=147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.rslly.top\/index.php\/wp-json\/wp\/v2\/tags?post=147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}