单例模式
1 public class Singleton { 2 3 private Singleton(){ 4 //do something 5 } 6 7 private static volatile Singleton singleton = null; 8 9 public static Singleton getInstance(){ 10 if (singleton == null){ 11 synchronized (Singleton.class){ 12 if (singleton == null){ 13 singleton = new Singleton(); 14 } 15 } 16 } 17 return singleton; 18 } 19 }