title: java singleton instantiation
body: <p>I've found three ways of instantiating a Singleton, but I have doubts as to whether any of them is the best there is. I'm using them in a multi-threaded environment and prefer lazy instantiation.<br>
  Sample 1:  </p>
  
  <pre><code>private static final ClassName INSTANCE = new ClassName();
  
  public static ClassName getInstance() {
      return INSTANCE;
  }
  </code></pre>
  
  <p>Sample 2:</p>
  
  <pre><code>private static class SingletonHolder { 
      public static final ClassName INSTANCE = new ClassName();
  }
  
  public static ClassName getInstance() {
      return SingletonHolder.INSTANCE;
  }
  </code></pre>
  
  <p>Sample 3:</p>
  
  <pre><code>private static ClassName INSTANCE;
  
  public static synchronized ClassName getInstance()
  {
      if (INSTANCE == null)
          INSTANCE = new ClassName();
  
      return INSTANCE;
  }
  </code></pre>
  
  <p>The project I'm using ATM uses Sample 2 everywhere, but I kind of like Sample 3 more. There is also the Enum version, but I just don't get it.  </p>
  
  <p>The question here is - in which cases I should/shouldn't use any of these variations? I'm not looking for lengthy explanations though (there's plenty of other topics about that, but they all eventually turn into arguing IMO), I'd like it to be understandable with few words.</p>