title: Thread Safe Efficient way to implement singleton pattern in Java?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/70689/efficient-way-to-implement-singleton-pattern-in-java">Efficient way to implement singleton pattern in Java</a>  </p>
  </blockquote>
  
  
  
  <p>I was reading this <a href="https://stackoverflow.com/questions/70689/best-singleton-implementation-in-java">Best Singleton Implementation In Java</a>, but its not thread safe.</p>
  
  <p>As per wiki :</p>
  
  <blockquote>
    <p><code>if(singleton==null)  { 
    synchronized(Singleton.class) { //
    this is needed if two threads are
    waiting at the monitor at the // time
    when singleton was getting
    instantiated  if(singleton==null) 
    singleton= new Singleton();  }<br>
    }
    </code></p>
  </blockquote>
  
  <p>But Find Bugs utility gives two errors in this : 
  1. Double null check. 
  2. Incorrect lazy initialization of static field.</p>
  
  <p>What is the best way,</p>
  
  <p>Is it Correct :</p>
  
  <blockquote>
  <pre><code>synchronized (Singleton.class) {
  if (singleton== null) {
  singleton= new Singleton();
  }
  }
  </code></pre>
  </blockquote>