Java ?????????: ?????? volatile ???? ??????
???????????? ???????[ 2013/9/29 15:26:27 ] ????????
????volatile ??????
??????漸???????????????????????????????Щ??????? volatile ??????ò????????????????????????????????????У?volatile ?????????????????????
????volatile ?????????????????????????????????????????????????Щ???????????????????????????С??????????????????????????????? volatile ??????????????????????????????????????????????????????????????????檔???????Щ??????????????????????????????????????????? —— ??????????????????????????????????????????????????????????????????????????????????????????ò??????????????????????????????????
?????? #5?????????????д??????
???????????????????? volatile ????????????????????????? ++x ?????????????????????????洢???????????????????????????? volatile ???????????????????????????????п???????
????????????????????????д???????????????????????? volatile ?????????????????·??????????嵥 6 ?????????????????????? synchronized ??????????????????????? volatile ??????????????????????2??????????÷??????????????????????·????????????漰 volatile ????????????????????????????????????????
?????嵥 6. ?????? volatile ?? synchronized ??? “???????????д??”
?????嵥 6. ?????? volatile ?? synchronized ??? “???????????д??” ?? 6. ?????? volatile ?? synchronized ??? “???????????д??”
@ThreadSafe
public class CheesyCounter {
// Employs the cheap read-write lock trick
// All mutative operations MUST be done with the 'this' lock held
@GuardedBy("this") private volatile int value;
public int getValue() { return value; }
public synchronized int increment() {
return value++;
}
}
|
????????????????????? “???????????д??” ?????????????????????????ж?д??????????????е?д????Υ??????? volatile ????????????????????? volatile ????????????? —— ???????????????????????????????????? volatile ????????????????????????????????б仯?????????? volatile ????????????????У???????????????????????volatile ???????????ж?????????????? volatile ?????????·???????????????????????·????????????? —— ?????д???????????????????μ??????????????????????????????????????????????????????????÷???????
??????????
????????????Volatile ????????????????????????????????????????Щ????????????????????????????????????? volatile ????????? —— ??????????????????????????????????? —— ???Щ??????????? volatile ???? synchronized ???????????????? volatile ?????????????????????????????????????????????????????? volatile ???? synchronized ????????Щ???????????Щ?????????????????????????????????????????????????????????? volatile ???????????????
??????
???·???
??????????????????
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