单例类,线程安全懒加载。

单例模式的七种写法:
http://cantellow.iteye.com/blog/838473

双重校验锁:
public class Singleton {

	private volatile static Singleton singleton;  
    private Singleton (){}  
    public static Singleton getSingleton() {  
	    if (singleton == null) {  
	        synchronized (Singleton.class) {  
		        if (singleton == null) {  
		            singleton = new Singleton();  
		        }  
	        }  
	    }  
	    return singleton;  
	}  
}

猜你喜欢

转载自572327713.iteye.com/blog/2408017
今日推荐