单例模式

单例模式,只上代码,不解释

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

public class {
private final static Singleton instance = new Singleton();
private static boolean initialized = false;
private (){
super()
}
private init(){

}
public statice synchronized Singleton getInstance(){
if (initialized) return instance;
instance.init();
initialized = true;
return instance;
}
}