title: How to test thread safety of a class from multiple threads?
body: <p>I am working on thread safe singleton class and I know below code is not thread safe because I am making a double check locking error.</p>
  
  <pre><code>protected static TestSingleton instance;
  
  private TestSingleton() {
      // some code
  }
  
  public static synchronized void setup() {
      if (instance == null) {
          TestSingleton holder = new TestSingleton();
          instance = holder;
      }
  }
  
  public static TestSingleton getInstance() {
      if (instance == null) {
          setup();
      }
      return instance;
  }
  </code></pre>
  
  <p>But I am trying to test this out so that I can prove it programmatically that this is not thread safe class. This is for my learning experience. </p>
  
  <p>How can I test this programmatically and prove it is not thread safe? </p>