title: ConcurrentHashMap as singletone cache with synchronized
body: <p>how do you think, <strong>do we need to use synchronized block for better optimization</strong> of access to instance of Ad? 
  The instance of Ad.class can be retrieved from different threads. Synchronized helps to get an instance in one time with one get operation from ConcurrentHashMap. ConcurrentHashMap store all values as volatile. I use it on java 1.7 for android, <strong>computeIfAbsent</strong> is available in java 1.8.</p>
  
  <p>It will be great to get detailed answer, why not or why yes.
  Thank you!</p>
  
  <pre><code>public final class Ad {
  
      private final static Map&lt;String, Ad&gt; ads = new ConcurrentHashMap&lt;&gt;();
  
      public static Ad get(@NonNull String appId) {
          if (appId == null) appId = "";
  
          boolean containsAd = ads.containsKey(appId);
  
          Ad localInstance = containsAd ? ads.get(appId) : null;
  
          if (localInstance == null) {
              synchronized (Ad.class) {
  
                  containsAd = ads.containsKey(appId);
  
                  localInstance = containsAd ? ads.get(appId) : null;
  
                  if (localInstance == null) {
                      localInstance = new Ad();
                      localInstance.setAdId(appId);
                      ads.put(appId, localInstance);
                  }
              }
          }
          return localInstance;
      }
  
      private Ad() {
      }
  }
  </code></pre>
  
  <p><strong>UPDATE</strong>: Thanks to all for help. I replaced ConcurrentHashMap to HashMap.</p>