forked from damaohongtu/JavaInterview
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSingleton.java
More file actions
25 lines (23 loc) · 628 Bytes
/
Singleton.java
File metadata and controls
25 lines (23 loc) · 628 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package JavaBasic;
import java.util.ArrayList;
import java.util.concurrent.Executors;
/**
* @Classname Singleton
* @Description 实现单例模式
* @Date 19-6-27 下午2:12
* @Created by mao<tianmao818@qq.com>
*/
public class Singleton {
private volatile static Singleton uniqueInstance;
private Singleton(){}
public static Singleton getUniqueInstance(){
if(uniqueInstance==null){
synchronized (Singleton.class){
if(uniqueInstance==null){
uniqueInstance=new Singleton();
}
}
}
return uniqueInstance;
}
}