{"id":3961,"date":"2019-03-05T18:59:19","date_gmt":"2019-03-05T10:59:19","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=3961"},"modified":"2019-03-05T18:59:19","modified_gmt":"2019-03-05T10:59:19","slug":"10w-%e9%9d%a2%e8%af%95%e9%a2%98%ef%bc%8chappens-before-%e8%a7%84%e5%88%99","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=3961","title":{"rendered":"10W+ \u9762\u8bd5\u9898\uff0chappens-before \u89c4\u5219"},"content":{"rendered":"<p>\n\t\u4eca\u5e74\u7684\u9762\u8bd5\u60c5\u51b5\uff0c\u88ab\u5f88\u591a\u4eba\u5410\u69fd\u3002\u53ef\u80fd\u662f\u4eba\u6570\u548c\u96be\u5ea6\u90fd\u6709\u6240\u589e\u52a0\u3002\n<\/p>\n<p>\n\t\u6628\u5929\u8fd8\u6709\u7f51\u53cb\u79c1\u4fe1\u6211\uff0c\u8bf4\u9762\u8bd5\u88ab\u95ee\u5230 happens-before \u89c4\u5219\uff0c\u6211\u8be5\u600e\u4e48\u56de\u7b54\uff1f\u8fd9\u4e2a\u8bf4\u6765\u8bdd\u957f\uff0c\u7ed9\u4ed6\u53d1\u4e86\u51e0\u4e2a\u94fe\u63a5\uff0c\u5e76\u63a8\u8350\u4ed6\u770b\u770b\u300a<a href=\"https:\/\/mp.weixin.qq.com\/s\/49DoVzXThnUGCB_3XLBfEw\" name=\"2019 Java \u9ad8\u5e76\u53d1\u5b66\u4e60\u8def\u7ebf\u56fe\u548c\u5fc5\u4f1a\u7684 50 \u9053\u9762\u8bd5\u9898\uff01\" target=\"_blank\" title=\"2019 Java \u9ad8\u5e76\u53d1\u5b66\u4e60\u8def\u7ebf\u56fe\u548c\u5fc5\u4f1a\u7684 50 \u9053\u9762\u8bd5\u9898\uff01\">2019 Java \u9ad8\u5e76\u53d1\u5b66\u4e60\u8def\u7ebf\u56fe\u548c\u5fc5\u4f1a\u7684 50 \u9053\u9762\u8bd5\u9898\uff01<\/a>\u300b\u8fd9\u4e2a\u3002\n<\/p>\n<p>\n\t\u8fc7\u6765\u4e00\u4f1a\u4ed6\uff0c\u53c8\u6765\u4e86\uff0c\u8bf4\u7f51\u4e0a\u7684\u89e3\u91ca\u6211\u770b\u4e0d\u61c2\u3002\u80fd\u4e0d\u80fd\u8ba9\u6211\u901a\u4fd7\u7684\u7ed9\u4ed6\u8bb2\u4e00\u4e0b\u3002\n<\/p>\n<p>\n\t\u5173\u4e8e happens-before \u89c4\u5219\uff0c\u6211\u6709\u4e00\u7bc7\u6587\u7ae0\uff08\u975e\u516c\u4f17\u53f7\uff09\u9760\u81ea\u7136\u641c\u7d22\u5df2\u7ecf\u8fbe\u5230 10w+ \u7684\u9605\u8bfb\u4e86\u3002\n<\/p>\n<p>\n\t\u6240\u4ee5\uff0c\u5c31\u501f\u8fd9\u4e2a\u65f6\u95f4\u7ed9\u5927\u5bb6\u901a\u4fd7\u7684\u8bb2\u4e00\u4e0b Happens-Before \u5427\u3002\n<\/p>\n<p>\n\thappens-before \u662f\u4ece JDK5 \u5f00\u59cb\uff0cjava \u4f7f\u7528\u65b0\u7684 JSR -133 \u5185\u5b58\u6a21\u578b\u63a8\u51fa\u7684\u4e00\u4e2a\u89c4\u5219\u3002JSR-133 \u4f7f\u7528 happens-before \u7684\u6982\u5ff5\u6765\u9610\u8ff0\u64cd\u4f5c\u4e4b\u95f4\u7684\u5185\u5b58\u53ef\u89c1\u6027\u3002\u5728 JMM \u4e2d\uff0c\u5982\u679c\u4e00\u4e2a\u64cd\u4f5c\u6267\u884c\u7684\u7ed3\u679c\u9700\u8981\u5bf9\u53e6\u4e00\u4e2a\u64cd\u4f5c\u53ef\u89c1\uff0c\u90a3\u4e48\u8fd9\u4e24\u4e2a\u64cd\u4f5c\u4e4b\u95f4\u5fc5\u987b\u8981\u5b58\u5728 happens-before \u5173\u7cfb\u3002\u8fd9\u91cc\u63d0\u5230\u7684\u4e24\u4e2a\u64cd\u4f5c\u65e2\u53ef\u4ee5\u662f\u5728\u4e00\u4e2a\u7ebf\u7a0b\u4e4b\u5185\uff0c\u4e5f\u53ef\u4ee5\u662f\u5728\u4e0d\u540c\u7ebf\u7a0b\u4e4b\u95f4\u3002<br \/>\n\t\u4e0e\u7a0b\u5e8f\u5458\u5bc6\u5207\u76f8\u5173\u7684 happens-before \u89c4\u5219\u5982\u4e0b\uff1a\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"happens-before \u89c4\u5219\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1g0s49dvmt2j20l906v0u2.jpg\" style=\"width: 765px;height: 247px\" \/>\n<\/p>\n<p>\n\t\u7ffb\u8bd1\u89e3\u91ca\u5982\u4e0b\uff1a\n<\/p>\n<ul>\n<li>\n\t\t\u7a0b\u5e8f\u6b21\u5e8f\u89c4\u5219\uff1a\u4e00\u4e2a\u7ebf\u7a0b\u5185\uff0c\u6309\u7167\u4ee3\u7801\u987a\u5e8f\uff0c\u4e66\u5199\u5728\u524d\u9762\u7684\u64cd\u4f5c happens-before \u4e8e\u4e66\u5199\u5728\u540e\u9762\u7684\u64cd\u4f5c\uff1b\n\t<\/li>\n<li>\n\t\t\u9501\u5b9a\u89c4\u5219\uff1a\u4e00\u4e2a unLock \u64cd\u4f5c\u5148\u884c\u53d1\u751f\u4e8e\u540e\u9762\u5bf9\u540c\u4e00\u4e2a\u9501\u989d lock \u64cd\u4f5c\uff1b\n\t<\/li>\n<li>\n\t\tvolatile\u53d8\u91cf\u89c4\u5219\uff1a\u5bf9\u4e00\u4e2a\u53d8\u91cf\u7684\u5199\u64cd\u4f5c\u5148\u884c\u53d1\u751f\u4e8e\u540e\u9762\u5bf9\u8fd9\u4e2a\u53d8\u91cf\u7684\u8bfb\u64cd\u4f5c\uff1b\n\t<\/li>\n<li>\n\t\t\u4f20\u9012\u89c4\u5219\uff1a\u5982\u679c\u64cd\u4f5cA\u5148\u884c\u53d1\u751f\u4e8e\u64cd\u4f5cB\uff0c\u800c\u64cd\u4f5cB\u53c8\u5148\u884c\u53d1\u751f\u4e8e\u64cd\u4f5cC\uff0c\u5219\u53ef\u4ee5\u5f97\u51fa\u64cd\u4f5cA\u5148\u884c\u53d1\u751f\u4e8e\u64cd\u4f5cC\uff1b\n\t<\/li>\n<li>\n\t\t\u7ebf\u7a0b\u542f\u52a8\u89c4\u5219\uff1aThread\u5bf9\u8c61\u7684start()\u65b9\u6cd5\u5148\u884c\u53d1\u751f\u4e8e\u6b64\u7ebf\u7a0b\u7684\u6bcf\u4e2a\u4e00\u4e2a\u52a8\u4f5c\uff1b\n\t<\/li>\n<li>\n\t\t\u7ebf\u7a0b\u4e2d\u65ad\u89c4\u5219\uff1a\u5bf9\u7ebf\u7a0binterrupt()\u65b9\u6cd5\u7684\u8c03\u7528\u5148\u884c\u53d1\u751f\u4e8e\u88ab\u4e2d\u65ad\u7ebf\u7a0b\u7684\u4ee3\u7801\u68c0\u6d4b\u5230\u4e2d\u65ad\u4e8b\u4ef6\u7684\u53d1\u751f\uff1b\n\t<\/li>\n<li>\n\t\t\u7ebf\u7a0b\u7ec8\u7ed3\u89c4\u5219\uff1a\u7ebf\u7a0b\u4e2d\u6240\u6709\u7684\u64cd\u4f5c\u90fd\u5148\u884c\u53d1\u751f\u4e8e\u7ebf\u7a0b\u7684\u7ec8\u6b62\u68c0\u6d4b\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7Thread.join()\u65b9\u6cd5\u7ed3\u675f\u3001Thread.isAlive()\u7684\u8fd4\u56de\u503c\u624b\u6bb5\u68c0\u6d4b\u5230\u7ebf\u7a0b\u5df2\u7ecf\u7ec8\u6b62\u6267\u884c\uff1b\n\t<\/li>\n<li>\n\t\t\u5bf9\u8c61\u7ec8\u7ed3\u89c4\u5219\uff1a\u4e00\u4e2a\u5bf9\u8c61\u7684\u521d\u59cb\u5316\u5b8c\u6210\u5148\u884c\u53d1\u751f\u4e8e\u4ed6\u7684finalize()\u65b9\u6cd5\u7684\u5f00\u59cb\uff1b\n\t<\/li>\n<\/ul>\n<p>\n\t\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u4e24\u4e2a\u64cd\u4f5c\u4e4b\u95f4\u5177\u6709 happens-before \u5173\u7cfb\uff0c\u5e76\u4e0d\u610f\u5473\u7740\u524d\u4e00\u4e2a\u64cd\u4f5c\u5fc5\u987b\u8981\u5728\u540e\u4e00\u4e2a\u64cd\u4f5c\u4e4b\u524d\u6267\u884c\uff01happens-before \u4ec5\u4ec5\u8981\u6c42\u524d\u4e00\u4e2a\u64cd\u4f5c\uff08\u6267\u884c\u7684\u7ed3\u679c\uff09\u5bf9\u540e\u4e00\u4e2a\u64cd\u4f5c\u53ef\u89c1\uff0c\u4e14\u524d\u4e00\u4e2a\u64cd\u4f5c\u6309\u987a\u5e8f\u6392\u5728\u7b2c\u4e8c\u4e2a\u64cd\u4f5c\u4e4b\u524d\uff08the first is visible to and ordered before the second\uff09\u3002happens- before \u7684\u5b9a\u4e49\u5f88\u5fae\u5999\uff0c\u5b83\u53ef\u4ee5\u770b\u4f5c java \u5185\u5b58\u6a21\u578b\u4e2d\u7684\u4e00\u6761\u89c4\u5219\u3002\n<\/p>\n<h2>\n\t\u53c2\u8003\u8d44\u6599<br \/>\n<\/h2>\n<ul>\n<li>\n\t\t<a href=\"https:\/\/docs.oracle.com\/javase\/specs\/jls\/se8\/html\/jls-17.html#jls-17.4.5\">https:\/\/docs.oracle.com\/javase\/specs\/jls\/se8\/html\/jls-17.html#jls-17.4.5<\/a>\n\t<\/li>\n<\/ul>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=3961\">10W+ \u9762\u8bd5\u9898\uff0chappens-before \u89c4\u5219<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5e74\u7684\u9762\u8bd5\u60c5\u51b5\uff0c\u88ab\u5f88\u591a\u4eba\u5410\u69fd\u3002\u53ef\u80fd\u662f\u4eba\u6570\u548c\u96be\u5ea6\u90fd\u6709\u6240\u589e\u52a0\u3002 \u6628\u5929\u8fd8\u6709\u7f51\u53cb\u79c1\u4fe1\u6211\uff0c\u8bf4\u9762\u8bd5\u88ab\u95ee\u5230 happens- [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[567,731,1647,472,410],"class_list":["post-3961","post","type-post","status-publish","format-standard","hentry","category-java","tag-java-","tag-jvm","tag-rest","tag-410"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3961","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3961"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3961\/revisions"}],"predecessor-version":[{"id":3962,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3961\/revisions\/3962"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3961"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3961"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3961"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}