Java???????????????
???????????? ???????[ 2014/5/22 11:32:36 ] ????????Java ??????????
??????????
????synchronized(this)??synchronized(MyClass.class)??????????synchronized??????????????????synchronized????????????
????synchronized???????ó????????????????????
public class Singleton {
private volatile static Singleton singleton;
private Singleton (){}
public static Singleton getSingleton() {
if (singleton == null) {
synchronized (Singleton.class) {
if (singleton == null) {
singleton = new Singleton();
}
}
}
return singleton;
}
}
|
??????????????????????????????????й?????????????????????????????????????????°??java?????????
???????????????????????????????????????????????????????????????????????????????????????????????飩
//???????????????????
public class Singleton {
private static class SingletonHolder {
private static final Singleton INSTANCE = new Singleton();
}
private Singleton (){}
public static final Singleton getInstance() {
return SingletonHolder.INSTANCE;
}
}
|
public class Singleton {
private static Singleton instance = new Singleton();
private Singleton (){}
public static Singleton getInstance() {
return instance;
}
}
|
????volatile????????????????е????????????????????????????????????????
??????synchronized???α?????get??set??????????????????volatile???α????????Ч?????????????????synchronized???????????????????????????????????棬??????????ж????????±????????????synchronized???л????Ч??????????Ч???????????????????synchronized??????????????С??????????????????????volatile??????volatile??????????????á?
??????

???·???
App??С????H5?????????????????Щ??
2024/9/11 15:34:34?????????????????????????
2024/9/10 11:13:49P-One ???????????????????????????????????????
2024/9/10 10:14:12???????????????????????????
2024/9/9 18:04:26??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44