Code example for ConcurrentHashMap

Methods: get, putIfAbsent

0
    } 
 
    @Override 
    public Cache getCacheByPool(String poolName) { 
 
        MockCache cache = caches.get(poolName); 
        if (cache == null) { 
            cache = new MockCache(poolName); 
 
            MockCache cacheExist = caches.putIfAbsent(poolName, cache); 
            if (cacheExist != null) { 
                cache = cacheExist; 
            } 
        } 
 
        return cache; 
    } 
}