`
wuhaowei12345
  • 浏览: 44191 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

java单例

 
阅读更多
public class Singleton4 {
   private static volatile Singleton4 instance;
    /** *//**
     * 双重加锁实现多线程运用和性能优化
     * @return
     */
    public static Singleton4 getInstance()
    {
      if (instance == null)
      {
        synchronized(Singleton4.class) {  //1
          if (instance == null)          //2
            instance = new Singleton4();  //3
        }
      }
      return instance;
    }
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics