do we need volatile when implementing singleton using double-check locking
问题 suppose we use double-check lock to implement singleton pattern: private static Singleton instance; private static Object lock = new Object(); public static Singleton getInstance() { if(instance == null) { synchronized (lock) { if(instance == null) { instance = new Singleton(); } } } return instance; } Do we need to set variable "instance" as "volatile"? I hear a saying that we need it to disable reordering: When an object is created , reordering may happen: address=alloc instance=someAddress