典型的单例模式

xiaoxiao2026-03-11  12

public class Singleton{ private static Singleton instance; //私有化构造方法来防止外部通过new 来创建该类的实例 private Singleton (){ } //使用 synchronzied 保证线程安全 public synchronized static Singleton getInstance(){ if(instance==null){ instance= new Singleton(); } return instance; }}
转载请注明原文地址: https://www.6miu.com/read-5045734.html

最新回复(0)