title: How to solve the "Double-Checked Locking is Broken" Declaration in Java?
body: <p>I want to implement lazy initialization for multithreading in Java.<br>
  I have some code of the sort:</p>
  
  <pre><code>class Foo {
      private Helper helper = null;
      public Helper getHelper() {
          if (helper == null) {
              Helper h;
              synchronized(this) {
                  h = helper;
                  if (h == null) 
                      synchronized (this) {
                          h = new Helper();
                      } // release inner synchronization lock
                  helper = h;
              } 
          }    
          return helper;
      }
      // other functions and members...
  }
  </code></pre>
  
  <p>And I'm getting the the "Double-Checked Locking is Broken" declaration.<br>
  How can I solve this?</p>