当前位置: 代码迷 >> 综合 >> 单例的双重检测实现
  详细解决方案

单例的双重检测实现

热度:65   发布时间:2024-02-21 12:19:09.0
public class Singleton {//禁止指令重排序优化private volatile static Singleton instance;private Singleton() {}public static Singleton getInstance() {//第一次检测if(instance == null) {synchronized(Singleton.class) {if(instance == null) {instance = new Singleton();}}}return instance;}
}

 

  相关解决方案