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; } }