Why is volatile used in double checked locking
问题 From Head First design patterns book, the singleton pattern with double checked locking has been implemented as below: public class Singleton { private volatile static Singleton instance; private Singleton() {} public static Singleton getInstance() { if (instance == null) { synchronized (Singleton.class) { if (instance == null) { instance = new Singleton(); } } } return instance; } } I don\'t understand why volatile is being used. Doesn\'t volatile usage defeat the purpose of using double