title: AsyncResponse and Java 8 parallel stream issue
body: <p>I am using spring boot with <code>Jersey rest api</code> </p>
  
  <pre><code>@POST
  @Path("test")
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.APPLICATION_JSON)
  public void test(final List&lt;String&gt; requests, @Suspended final AsyncResponse asyncResponse) {
  
      List&lt;String&gt; resplist = new ArrayList();
      requests.parallelStream().forEach(req -&gt; {
  
          String resp = //some process to get (Always return string)
          resplist.add(resp);
      });
  
      asyncResponse.resume(resplist);
  
  }
  </code></pre>
  
  <p>If I use <code>parallelStream</code> sometimes the list that is retrieved on the client side does not return all the elements. </p>
  
  <p>Lets say I pass 30 it returns 29 but sometime it does return 30 (Request is always the same)</p>
  
  <p>But If I use normal stream with <strong><code>forEach</code></strong> only, then it always returns me 30 elements.</p>
  
  <p>Is this some sort of bug? Can I not use parallelStream in rest api</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>As answered by Eugene this was the issue because when using parallel stream multiple threads were adding record into arraylist which is not threadsafe</p>
  
  <p><strong>solution</strong> 
  Use Synch collection</p>
  
  <pre><code>Collection&lt;String&gt; resplist = Collections.synchronizedCollection(new ArrayList&lt;String&gt;());
  </code></pre>