java设计模式之单例模式(双重加锁懒汉)

package src.test.java.com.pbc.singleton;
/**
 * (双重加锁懒汉)单例模式
 * @author qiu_y
 *
 */
public class DoubleLockSingleton {
 private static DoubleLockSingleton doubleLockSingleton = null;
 /**
  * 私有构造器
  */
 private DoubleLockSingleton() {}
 /**
  * 双重加锁懒汉单例
  * 懒加载,线程安全,效率高
  */
 public static DoubleLockSingleton getInstince() {
  if(null == doubleLockSingleton) {
   synchronized (DoubleLockSingleton.class) {
    if (null == doubleLockSingleton) {
     doubleLockSingleton = new DoubleLockSingleton();
    }
   }
   
  }
  return doubleLockSingleton;
 }
}
posted @ 2020-07-03 17:08  尚进生  阅读(1258)  评论(0编辑  收藏  举报