单例模式 (二) 延迟加载/"懒汉模式" —— 使用DCL双检查锁机制

 
  
package com.multithreading;

/**
 * Created by nanzhou on 2017/6/30.
 */
public class Singleton {

    private volatile static Singleton singleton;


    private Singleton() {

    }

    public static Singleton getIntance() {


        if (null == singleton) {


            synchronized (Singleton.class) {


                if (null == singleton) {

                    singleton =  new Singleton();
                }
            }
        }

            return singleton;
        }
    }



你可能感兴趣的:(单例模式,多线程)