Java??????????????д??
???????????? ???????[ 2013/12/20 9:39:05 ] ????????
???????????????????????????
1 public class Singleton {
2 private static Singleton instance;
3 private Singleton (){}
4 public static Singleton getInstance() {
5 if (instance == null) {
6 instance = new Singleton();
7 }
8 return instance;
9 }
10 }
|
????????д??lazy loading??????????????????????????????????????
?????????????????????????
1 public class Singleton {
2 private static Singleton instance;
3 private Singleton (){}
4 public static synchronized Singleton getInstance() {
5 if (instance == null) {
6 instance = new Singleton();
7 }
8 return instance;
9 }
10 }
11
|
????????д????????????к???????????????????????????lazy loading???????????????Ч?????99%????2?????????
???????????????????.
``````````````````````````````````````````````````
??????????????classloder???????????????????????????instance????????????????????????????????к?????????????д???????????getInstance?????? ?????????????????????????????????????????????????????????????instance?????д?lazy loading??Ч????
????????????????????????
1 public class Singleton {
2 private Singleton instance = null;
3 static {
4 instance = new Singleton();
5 }
6 private Singleton (){}
7 public static Singleton getInstance() {
8 return this.instance;
9 }
10 }
|
?????????????????????????????????????????????????????????instance??
??????
![](/images/ad-banner/ad-banner.png)
???·???
??????????????????
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