Skip to content

Commit b11ae91

Browse files
committed
添加线程安全的懒汉写法的单例模式
1 parent 11d23bf commit b11ae91

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package cn.byhieg.designpatterntutorial.singleton;
2+
3+
/**
4+
* Created by shiqifeng on 2017/3/14.
5+
* Mail byhieg@gmail.com
6+
*/
7+
public class DCLSingleton {
8+
9+
private static volatile DCLSingleton singleton;
10+
11+
private DCLSingleton(){
12+
13+
}
14+
15+
public static DCLSingleton getSingleton(){
16+
if (singleton == null) {
17+
synchronized (DCLSingleton.class) {
18+
if (singleton == null) {
19+
singleton = new DCLSingleton();
20+
}
21+
}
22+
}
23+
return singleton;
24+
}
25+
26+
}

0 commit comments

Comments
 (0)