/**
* Created by qiyei2015 on 2017/5/13.
*/
public class Instance {
private volatile static Instance ins = null;
/**
* 构造方法私有化
*/
private Instance(){
}
/**
* 懒汉式获取单例
* @return
*/
public static Instance getInstance(){
if (ins == null){
synchronized (Instance.class){
if (ins == null){
ins = new Instance();
}
}
}
return ins;
}
}
volatile 存在的意义就是解决 synchronized的时候 ,java乱序问题,