title: How to correctly make a thread safe Singleton Factory in Java?
body: <p>This is the first time I am writing a <code>Factory</code> class. Below is my Factory class, I am not sure whether this is the correct way of making thread safe Singleton Factory class or not. I will be returning instance of my Client using this factory?</p>
  
  <pre><code>public class ClientFactory {
  
      private static ClientFactory instance = null;   
  
      private ClientFactory() {
  
      }
  
      public static ClientFactory getInstance() {
  
          if (instance == null)
          {
              instance =  new ClientFactory();
          }
  
          return instance;
      }
  
      public IClient getClient() {
  
          return new TestClient();
      }
  }
  </code></pre>
  
  <p>And here is my TestClient class - </p>
  
  <pre><code>public class TestClient implements IClient {
  
  
  }
  </code></pre>
  
  <p>And this is how I am going to use my factory - </p>
  
  <pre><code>IClient client = ClientFactory.getInstance().getClient();
  </code></pre>