title: Thread safety in Singleton
body: <p>I understand that double locking in Java is broken, so what are the best ways to make Singletons Thread Safe in Java?  The first thing that springs to my mind is:</p>
  
  <pre><code>class Singleton{
      private static Singleton instance;
  
      private Singleton(){}
  
      public static synchronized Singleton getInstance(){
          if(instance == null) instance = new Singleton();
          return instance;
      }
  }
  </code></pre>
  
  <p>Does this work? if so, is it the best way (I guess that depends on circumstances, so stating when a particular technique is best, would be useful)</p>