title: Java double checked locking
body: <p>I happened upon an article recently discussing the double checked locking pattern in Java and its pitfalls and now I'm wondering if a variant of that pattern that I've been using for years now is subject to any issues.</p>
  
  <p>I've looked at many posts and articles on the subject and understand the potential issues with getting a reference to a partially constructed object, and as far as I can tell, I don't <em>think</em> my implementation is subject to these issues. Are there any issues with the following pattern?</p>
  
  <p>And, if not, why don't people use it? I've never seen it recommended in any of the discussion I've seen around this issue.</p>
  
  <pre><code>public class Test {
      private static Test instance;
      private static boolean initialized = false;
  
      public static Test getInstance() {
          if (!initialized) {
              synchronized (Test.class) {
                  if (!initialized) {
                      instance = new Test();
                      initialized = true;
                  }
              }
          }
          return instance;
      }
  }
  </code></pre>