Java????????????
???????????? ???????[ 2016/11/2 10:56:12 ] ??????????? Java ???
????Java????????????????????????????????????????????乲??????????????????????д-??????е??????????????????????????????????????????????????????????????????????????????
???????????????е????????????????????????????δ?????????????以????С?
????1??????????
????1.1 ??????
????Java????????????Java???????JMM???????JMM???????????????????д??????????????????
??????????????????JMM????????????????????????????????????????洢??????棨main memory???У???????????????е??????棨local memory????????????д洢?????????/д???????????????????????JMM??????????????????????????????????棬д?????????????????????????????????????Java?????????????????£?
??????????????裺
????????????A????????A?и??1???????????μ?????????????????B????????????????A??????1???????????
???????????A??B????????й??????x??????????????????????????е?x????0?????A????????????o??x?????????1?????????????????????A?С??????A?????B???????????μ?????--??????????A???????????????????????x???μ???????У??????????е?x??????1????????B????????????????A???o??x?????????B?????????x???????1??
????????????????????????????????????A???????B??????????????????????????????????檔JMM???????????????????????????????????????java??????????????????
????1.2 ????????????
?????????????????乲????Count???????????????????????????????(?????)?У?????????????????????(????)?????????洢???????Count??????????????????????Count????????????????渴??Count????????????У??????д???count.count()???????num??????ù??????Count????????Count??
?????????????????????ж??????????????????????????????????????????????????????????????????????
???????????????????????????????????????????????CPU??????????????????????????????????е?????л???????????????????????????????л???????????????????100????????????????10????????????????????10???????????????100????????????????????????A?????????B????????A??????????100??B??????????100??A??м?10????????????????μ?????棬????????????100-10=90????B?????м?10????????????????μ?????棬???????????100+10=110?????????????????????????????A????B?????????У??????????????????????????????
????1.3 synchronized??volatile
????????????л????????????£?
??????????????????????棻??????濽????????????????棻
??????д???(????????????)??
?????????????????
??????????????
?????????synchronized????????????????????????????????????????
????volatile??????Java????????????Σ?????JLS???????????????????volatile???Σ????????????????????????????????????μ?????
????[java]view plaincopy
????print?
????classTest{ staticvolatileinti=0??j=0; staticvoidone(){ i++; j++; } staticvoidtwo(){ System.out.println("i="+i+"j="+j); } }
????????volatile????????????i??j??????????????????У??????????i??j????????????£????????????????two?????????????i??j??е?????????????????volatile???????????????????????????????
??????????volatile?????????й??????£?
??????????i??????濽??????????棻
?????????????????
???????i?????
??????????j??????濽??????????棻
?????????????????
???????j?????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11