title: How to safely modify values in Java HashMaps concurrently?
body: <p>I have a block of Java code that looks something like this that I'm trying to parallelize:</p>
  
  <pre><code>value = map.get(key);
  if (value == null) {
      value = new Value();
      map.put(key,value);
  }
  value.update();
  </code></pre>
  
  <p>I want to block any other thread from accessing the map with that particular key until after <code>value.update()</code> is called <em>even if key is not in the key set</em>.  Accessing with other keys should be allowed. How could I achieve this?</p>