title: Does below class implement correct Java Singleton Object and provide Thread Safety .. It seems so looking at my Unit Test Case
body: <pre><code>package samples.study;
  
  /**
   * 
   * @author
   */
  public class Singleton {
      private Singleton(){}
      private static final Singleton instance = new Singleton();
  
      public static Singleton getInstance() {
          System.out.println(Thread.currentThread().getName() + &quot; getInstance&quot;);
          return Singleton.instance;
      }
  }
  </code></pre>
  <p>Unit Test Case Seems to work fine and singleton objects are returned from Multiple threads. Help me spot any issues here ?</p>
  <pre><code>package samples.study;
  
  import static org.junit.jupiter.api.Assertions.assertSame;
  
  import java.util.ArrayList;
  import java.util.List;
  import java.util.concurrent.ExecutorService;
  import java.util.concurrent.Executors;
  
  import org.junit.jupiter.api.BeforeEach;
  import org.junit.jupiter.api.Test;
  
  class SingletonTest {
  
      @BeforeEach
      void setUp() throws Exception {
      }
  
      @Test
      void test() throws InterruptedException {
  
          ExecutorService s = Executors.newCachedThreadPool();
          Singleton obj = Singleton.getInstance();
          int threadCount = 10;
          List&lt;Singleton&gt; objList = new ArrayList&lt;Singleton&gt;();
          while (threadCount &gt; 0) {
              s.submit(() -&gt; {
                  objList.add(getInstance(s));
              });
              threadCount--;
          }
          while (threadCount &gt; 0) {
              assertSame(obj, objList.get(threadCount));
          }
      }
  
      public Singleton getInstance(ExecutorService s) {
          Singleton obj = Singleton.getInstance();
          System.out.println(&quot;1 = &quot; + Thread.currentThread().getName() + obj);
          return obj;
      }
  
  }
  </code></pre>
  <p>Result of UT :</p>
  <ul>
  <li>main getInstance pool-1-thread-3 getInstance pool-1-thread-2
  getInstance 1 = pool-1-thread-2samples.study.Singleton@75cbce36
  pool-1-thread-4 getInstance 1 =
  pool-1-thread-4samples.study.Singleton@75cbce36 pool-1-thread-8
  getInstance 1 = pool-1-thread-8samples.study.Singleton@75cbce36
  pool-1-thread-7 getInstance pool-1-thread-9 getInstance
  pool-1-thread-6 getInstance pool-1-thread-10 getInstance 1 =
  pool-1-thread-10samples.study.Singleton@75cbce36 1 =
  pool-1-thread-6samples.study.Singleton@75cbce36 pool-1-thread-5
  getInstance 1 = pool-1-thread-5samples.study.Singleton@75cbce36 1 =
  pool-1-thread-9samples.study.Singleton@75cbce36 1 =
  pool-1-thread-7samples.study.Singleton@75cbce36 pool-1-thread-1
  getInstance 1 = pool-1-thread-1samples.study.Singleton@75cbce36 1 =
  pool-1-thread-3samples.study.Singleton@75cbce36</li>
  </ul>