@SuppressWarnings("unchecked")
  @Override
  public <T> T retrieve(String key, Callable<T> fn) throws HiveException {

    T value = null;
    ReentrantLock objectLock = null;

    lock.lock();
    try {
      value = (T) registry.getIfPresent(key);
      if (value != null) {
        LOG.debug("Found {} in cache", key);
        return value;
      }

      if (locks.containsKey(key)) {
        objectLock = locks.get(key);
      } else {
        objectLock = new ReentrantLock();
        locks.put(key, objectLock);
      }
    } finally {
      lock.unlock();
    }

    objectLock.lock();
    try{
      lock.lock();
      try {
        value = (T) registry.getIfPresent(key);
        if (value != null) {
          LOG.debug("Found {} in cache", key);
          return value;
        }
      } finally {
        lock.unlock();
      }

      try {
        value = fn.call();
      } catch (Exception e) {
        throw new HiveException(e);
      }

      lock.lock();
      try {
        LOG.debug("Caching new object for key: {}", key);
        registry.put(key, value);
        locks.remove(key);
      } finally {
        lock.unlock();
      }
    } finally {
      objectLock.unlock();
    }
    return value;
  }
LlapObjectCache. Llap implementation for the shared object cache.
ql/src/java/org/apache/hadoop/hive/ql/exec/tez/LlapObjectCache.java