单例模式

package com.wdf;  
  
public class Singleton {  
  
    private volatile static Singleton singleton = null;  
  
    private Singleton() {  
  
    }  
  
    public static Singleton getInstance() {  
  
        if (singleton == null) {  
            synchronized (Singleton.class) {  
                //double checked locking  
                if (singleton == null) {  
                    singleton = new Singleton();  
                }  
            }  
  
        }  
  
        return singleton;  
  
    }  
}



你可能感兴趣的:(java单例模式)