package cn.xz.study.design.pattern.singleton;

public class LazySingleton {
	/**
	 * volatile 确保线程改变了变量的值时 会立刻同步改变量的值  以保证改变量的值是最新的
	 */
	private volatile static LazySingleton singleton = null;
	private LazySingleton(){
		
	}
	
	public static LazySingleton getInstance(){
		if(singleton == null){
			synchronized (LazySingleton.class){
				singleton = new LazySingleton();
			}
		}
		return singleton;
	}
	
	private int count = 0;
	public synchronized int add(){
		return count++;
	}

	public int getCount() {
		return count;
	}
	
}
