{"id":134936,"date":"2020-07-21T08:19:33","date_gmt":"2020-07-21T00:19:33","guid":{"rendered":"http:\/\/4563.org\/?p=134936"},"modified":"2020-07-21T08:19:33","modified_gmt":"2020-07-21T00:19:33","slug":"javaer-%e5%b8%ae%e5%bf%99%e7%9c%8b%e4%b8%8b%e4%b8%80%e4%b8%aa%e5%a4%9a%e7%ba%bf%e7%a8%8b%e7%9a%84%e5%b0%8f%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=134936","title":{"rendered":"Javaer \u5e2e\u5fd9\u770b\u4e0b\u4e00\u4e2a\u591a\u7ebf\u7a0b\u7684\u5c0f\u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Javaer \u5e2e\u5fd9\u770b\u4e0b\u4e00\u4e2a\u591a\u7ebf\u7a0b\u7684\u5c0f\u95ee\u9898               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : chanlk <\/span>  <span><i><\/i> 15<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u4e3b\u51fd\u6570\u5f00\u542f\u4e86\u4e24\u4e2a\u7ebf\u7a0b, \u5176\u4e2d\u4e00\u4e2a\u662f\u8d1f\u8d23\u589e\u52a0\u4e00\u4e2a Value \u7c7b\u4e2d\u7684\u9759\u6001\u53d8\u91cf, \u53e6\u4e00\u4e2a\u662f\u8d1f\u8d23\u68c0\u67e5\u8fd9\u4e2a\u9759\u6001\u53d8\u91cf\u7684\u503c,\u5f53\u8fd9\u4e2a\u503c\u8fbe\u5230\u4e00\u5b9a\u503c\u540e\u5c31\u5f00\u59cb\u6253\u5370;<\/p>\n<p>\u4e3a\u4ec0\u4e48\u4e0b\u9762\u8fd9\u6bb5\u7a0b\u5e8f\u7684 CheckThread \u4e0d\u80fd\u8f93\u51fa?\u90a3\u4e2a value \u7684\u503c\u5728\u51e0\u79d2\u949f\u65f6\u95f4\u5c31\u8d85\u8fc7 500000000 \u4e86<\/p>\n<p>\u53e6\u5916\u5947\u602a\u7684\u662f CheckThread \u5728 while(true)\u7684\u540e\u9762\u589e\u52a0\u4e00\u4e2a\u6253\u5370,\u5c31\u80fd\u8fdb if \u91cc\u9762\u4e86,\u8be6\u60c5\u89c1\u4ee3\u7801;<\/p>\n<p>\u4e0b\u9762\u662f\u4ee3\u7801:<\/p>\n<pre><code>class Scratch {     public static void main(String[] args) {         new IncreasingThread().start();         new CheckThread().start();     } }  class Value {     static long value = 0; }  class IncreasingThread extends Thread {     @Override     public void run() {         while (true) {             Value.value++;         }     } }  class CheckThread extends Thread {     @Override     public void run() {         while (true) {            \/\/ \u6253\u5f00\u4e0b\u9762\u7684\u8fd9\u884c\u6ce8\u91ca,\u5c31\u80fd\u8fdb\u53bb if \u91cc\u6267\u884c\u6253\u5370\u4e86            \/\/ System.out.println(Value.value);             if (Value.value &gt; 500000000) {                 System.out.println(\"value over 500000000\");             }         }     } } <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>10<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"2400504\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : snowydec <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             volatile \u5173\u952e\u5b57                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2400505\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zhgg0 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             println \u91cc\u9762\u6709\u4e2a\u9501\u3002\u6ca1\u6709\u9501\uff0c\u6ca1\u6709 volitale\uff0c\u7ebf\u7a0b\u4e4b\u95f4\u53d8\u91cf\u7684\u66f4\u6539\u4e0d\u53ef\u89c1\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2400506\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : amai0w0 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             system.out \u5185\u90e8\u52a0\u9501\uff0c\u95f4\u63a5\u4fdd\u8bc1\u4e86\u5185\u5b58\u53ef\u89c1\u6027\uff0c\u4e0d\u52a0\u6253\u5370\u7684\u8bdd\u5e94\u8be5\u628a value \u8bbe\u4e3a volatile \u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2400507\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : anakinsky <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             JMM \u4e86\u89e3\u4e0b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2400508\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : fubei <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             volatile                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2400509\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : chanlk <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8c22\u8c22\u5404\u4f4d,\u6211\u5f97\u53bb\u7cfb\u7edf\u7684\u5b66\u4e60\u4e0b\u8fd9\u65b9\u9762\u7684\u77e5\u8bc6\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2400510\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ChanKc <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5efa\u8bae\u53bb\u770b Effective Java \u548c Java lang spec                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2400511\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Jacky23333 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             value \u9700\u8981\u52a0\u4e2a volatile \u4fee\u9970\u4fdd\u8bc1\u53d8\u91cf\u7684\u53ef\u89c1\u6027\uff0c\u4e3b\u53ef\u4ee5\u770b\u770b java \u5185\u5b58\u6a21\u578b\u76f8\u5173\u7684\u5185\u5bb9                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2400512\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : serical <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             R \u5927\u6709\u89e3\u91ca\u8fc7\u8fd9\u4e2a\u95ee\u9898 https:\/\/www.zhihu.com\/question\/39458585\/answer\/81521474                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2400513\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : br00k <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6362\u6210 AtomicLong \u4e0d\u597d\u5417\uff1f\u7ebf\u7a0b\u5b89\u5168                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Javaer \u5e2e\u5fd9\u770b\u4e0b\u4e00\u4e2a\u591a\u7ebf\u7a0b\u7684&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/134936"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=134936"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/134936\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=134936"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=134936"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=134936"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}