title: Snippet for concurrentHashMap to retrieve object or create it if absent (as atomic operation)
body: <p>In Java, I want to do something like this: </p>
  
  <pre><code>   Object r = map.get(t);
     if (r == null) {
        r = create(); // creating r is an expensive operation.
        map.put(t, r);  
     }
  </code></pre>
  
  <p>Now that snippet of code can be executed in a multithreaded environment.
  <code>map</code> can be a ConcurrentHashMap.</p>
  
  <p>But how do I make that logic atomic?</p>
  
  <p>Please don't give me trivial solution like a 'synchronized' block.
  I 'd expect this problem can be solved neatly once and for all.</p>