JAVA设计模式之单例模式

package com.model.newb.danli;

/**
 * 使用双重校验锁
 * */
public class Singleton {

	private Singleton() {}
	private static volatile Singleton instance;
	public static Singleton getInstance(){
		if(instance == null){
			synchronized(Singleton.class){ // 锁的是类
				if(instance == null ){
					instance  = new Singleton();
				}
			}
		}
		return instance;
	
	}

}

  

posted on 2015-11-10 13:57  wzyy  阅读(233)  评论(0)    收藏  举报