标签:模式 span ola vol div 错误 instance ble vat
public class Singleton { private volatile static Singleton singleton; private Singleton() { } public Singleton getInstance() { if (null == singleton) { synchronized (Singleton.class) { if (null == singleton) { singleton = new Singleton(); } } } return singleton; } }
使用double check保证实例只初始化一次,使用volatile保证不会因为指令重排造成错误
标签:模式 span ola vol div 错误 instance ble vat
原文地址:https://www.cnblogs.com/yytxdy/p/11393513.html