懒汉式--单例设计模式

xiaoxiao2021-02-28  41

/**  * 懒汉式--单例设计模式  */ public class LazyUnSafeSingleton {     //私有化构造方法     private LazyUnSafeSingleton(){}     //定义引用     private static LazyUnSafeSingleton instance;     //获取对象方法     public static LazyUnSafeSingleton getInstance(){         if(instance == null){       //多个线程同时进入到这,会实例多个对象             instance = new LazyUnSafeSingleton();         }         return instance;     } }
转载请注明原文地址: https://www.6miu.com/read-2632445.html

最新回复(0)