title: What if we use only the outer null check in double check singleton pattern?
body: <p>Question 1: Why in singleton pattern for multi-threading we need two null checks? What if we use only the outer check?</p>
  
  <pre><code>    if (instance == null) {
          synchronized (ABC.class) {
  
              // What if we remove this check?
              if (instance == null) {
                  instance = new ABC();
              }
      }
  </code></pre>
  
  <p>Question 2: What's the difference between the following:</p>
  
  <h1>1: Using directly the class name inside synchronized()</h1>
  
  <pre><code>    public ABC getInstance() {
          if (instance == null) {
              // Difference here
              synchronized (ABC.class) {
                  if (instance == null) {
                      instance = new ABC();
                  }
              }
           }
           return instance;
      }
  </code></pre>
  
  <h1>2: Using a static final Object inside synchronized()</h1>
  
  <pre><code>    private static final Object LOCK = new Object();
      .
      .
      public ABC getInstance() {
          if (instance == null) {
  
               // Difference here
               synchronized (LOCK) {
                  if (instance == null) {
                      instance = new ABC();
                  }
               }
           }
           return instance;
      }
  </code></pre>
  
  <h1>3: Using <strong>new Object()</strong> inside synchronized()</h1>
  
  <pre><code>    if (instance == null) {
      // Difference here
           synchronized (new Object()) {
              if (instance == null) {
                  instance = new ABC();
              }
          }
       }
  </code></pre>