单例模式:确保一个类最多只有一个实例,并提供一个全局访问点

普通单例模式示例(有问题)

public class Singleton {

    private static Singleton uniqueInstance = null;

    private Singleton() {

    }

    public static Singleton getInstance() {
        if (uniqueInstance == null) {
            uniqueInstance = new Singleton();
        }
        return uniqueInstance;
    }

}
示例Singleton

相关文章: