Java????????Synchronized???????
???????????? ???????[ 2012/10/17 10:05:41 ] ????????
????????????
????????????????????????????????
???????????????????????????????????????????????????????
????????????????????????static??????????????????static???????
???????????????
????1???????ж??????????????з????
????2??????????? ????????????? ???????????з????????????????????????д????
?????????????????????????
??????????Synchronized??????????????????????????????????????? ???????????????????????????????
?????????з???????о????????μ????Ч??
????1??Synchronized ????????????????????????????????
????Java????
public class Demo1 { public synchronized void m1(){ //............... } public void m2(){ //............ synchronized(this){ //......... } //........ } } |
??????????д????Ч???????????????????????????????????? ????????? demo = new Demo1()???????????????? thread1??thread2??????????demo ??????????????????? thread1??????demo.m1()????thread2??????????????demo.m1() ?? demo.m2(); ???thread1??demo????????????????????????????????????
????????????thread1???? demo1.m1()??thread2???? demo2.m1()????????????У??????????????????Demo1??????????
????2??Synchronized ????????????????飬???????????
????Java????
|
????????????£??????????????????????????? ????a??b???????a ??b ?????static ??????????? ?????????demo = new Demo2()????????????????thread1??thread2??????????demo??????????????????? thread1??????demo.m1()????thread2??????????????demo.m2()??????????? demo.m1()??????飬???a?? thread1???????
??????
???·???
??????????????????
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