日期:2014-05-20 浏览次数:20619 次
public class A {
4
5 private static A instance;
6
7 private A(){}
8
9 public synchronized static A getInstance(){
10 if(instance == null){
11 instance = new A();
12 }
13 return instance;
14 }
15
16 }
public class B{
20
21 private static B instance;
22
23 private B(){}
24
25 public static B getInstance(){
26 if(instance == null){
27 instance = newInstance();
28 }
29 return instance;
30 }
31
32 private synchroized static B newInstance(){
33 if(instance == null){
34 instance = new B();
35 }
36 return instance;
37 }
38 }