title: Why Set.add() method does not work in anonymous Runnable?
body: <p>I would like to run 20 threads simultaneously to test my id generator. However, uniqueSet.add(id) is not adding id to the set. When I assert, it says set size is zero.</p>
  <pre><code>@Test
  void should_generate_unique_id_concurrently() throws InterruptedException {
      Set&lt;Long&gt; uniqueSet = ConcurrentHashMap.newKeySet();
      final int numberOfThreads = 20;
      ExecutorService service = Executors.newFixedThreadPool(numberOfThreads);
      CountDownLatch latch = new CountDownLatch(numberOfThreads);
      for (int i = 0; i &lt; numberOfThreads; i++) {
          service.submit(() -&gt; {
              try {
                  latch.countDown();
                  latch.await();
                  long id = idGenerator.nextId();
                  uniqueSet.add(id);
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
          });
      }
      assertEquals(numberOfThreads, uniqueSet.size());
  }
  </code></pre>