title: Is it optimal to use the double checked locking idiom for the singleton pattern?
body: <p>Is it better to use the double checked locking idiom for a singleton pattern? Or a synchronised method?</p>
  
  <p>ie:</p>
  
  <pre><code>private static volatile ProcessManager singleton = null;
  
  public static ProcessManager getInstance() throws Exception {
  
      if (singleton == null) {
         synchronized (MyClass.class) {
            if (singleton == null) {
                 singleton = new ProcessManager();
           }
        }
     }
     return singleton;
  </code></pre>
  
  <p>}</p>
  
  <p>or</p>
  
  <pre><code>private static processManager singleton = null;
  
  public synchronized static processManager getInsatnce() throws Exception {
  
     if(singleton == null) {
              singleton = new processManager();
      }
  
      return singleton
   }
  </code></pre>