title: Static Collection update inside CompletableFuture#runAsync
body: <p>Preconditions <strong>(generic description)</strong>:</p>
  
  <p><strong>1.</strong> static class field</p>
  
  <pre><code>static List&lt;String&gt; ids = new ArrayList&lt;&gt;();
  </code></pre>
  
  <p><strong>2.</strong>  <code>CompletableFuture#runAsync(Runnable runnable,Executor executor)</code></p>
  
  <p>called within
  <code>static void main(String args[])</code> method</p>
  
  <p><strong>3.</strong> elements added to <code>someCollection</code> inside of <code>runAsync</code> call from <strong>step2</strong></p>
  
  <p>Code snippet <strong>(specific description)</strong>:</p>
  
  <pre><code>private static List&lt;String&gt; ids = new ArrayList&lt;&gt;();
  
  public static void main(String[] args) throws ExecutionException, InterruptedException {
      //...
      final List&lt;String&gt; lines = Files.lines(path).collect(Collectors.toList());
      for (List&lt;String&gt; lines : CollectionUtils.split(1024, lines)) {
           CompletableFuture&lt;Void&gt; future = CompletableFuture.runAsync(() -&gt; {
               List&lt;User&gt; users = buildUsers();
               populate(users);
           }, executorService);
  
          futures.add(future);
      }
  
      private static void populate(List&lt;User&gt; users){
         //...
         ids.add(User.getId);
         //...
      }
  }
  </code></pre>
  
  <p><strong>Problem description:</strong></p>
  
  <p>As I understand from concurrency point of view,
  static variable could NOT be shared between threads, so data can be lost some way.</p>
  
  <p>Should it be changed to <code>volatile</code> or it would be reasonable to use
  <code>ConcurrentSkipListSet&lt;String&gt;</code> ?</p>