title: Updating elements atomically retrieving from Map using Java 8 parallel streams
body: <p>I have a parallel stream in which I'm using a Map to mutate the elements. </p>
  
  <pre><code>Map&lt;Long, List&lt;MyItem&gt;&gt; hashmap = foo.getMap();
  
  itemStream.parallel()
    .filter(Objects::nonNull)
    .forEach(item -&gt; setProperties(hashmap, item));
  </code></pre>
  
  <p>The method 'setProperties()' takes the map and item, and performs a get using item and then sets some attributes of the item.</p>
  
  <p>What I want is for the getting/property setting to be done atomically. So that two threads can't perform a get on the same key and have property updates be interleaved.</p>
  
  <pre><code>private void setProperties(Map&lt;Long, List&lt;Item&gt;&gt; map, Item item) {
      long id = item.getID();
      List&lt;Object1&gt; items = map.get(id);
      for (Object1 ob : items) {
              ob.setId(item.getFloorId());
              ob.setPath(item.getPath());
              ob.setTypeName(item.getTypeName());
      }
  }
  </code></pre>
  
  <p>Also a bit concerned about the latency hit and whether this sort of parallelization will really have a benefit vs the existing single threaded approach.</p>