private void doOneCleanupRound() throws InterruptedException {
    while (true) {
      int evictionsSinceLast = newEvictions.getAndSet(0);
      if (evictionsSinceLast > 0) break;

      // will be notified by SerDeLowLevelCacheImpl or timeout eventually
      synchronized (newEvictions) {
        newEvictions.wait(10000);
      }
    }
    // Duration is an estimate; if the size of the map changes, it can be very different.
    long endTime = System.nanoTime() + approxCleanupIntervalSec * 1000000000L;
    int leftToCheck = 0; // approximate
    for (FileCache<T> fc : fileMap.values()) {
      leftToCheck += getCacheSize(fc);
    }
    // Iterate thru all the filecaches. This is best-effort.
    // If these super-long-lived iterators affect the map in some bad way,
    // we'd need to sleep once per round instead.
    Iterator<Map.Entry<Object, FileCache<T>>> iter = fileMap.entrySet().iterator();
    Ref<Boolean> isPastEndTime = Ref.from(false);
    while (iter.hasNext()) {
      FileCache<T> fc = iter.next().getValue();
      if (!fc.incRef()) {
        throw new AssertionError("Something other than cleanup is removing elements from map");
      }
      leftToCheck = cleanUpOneFileCache(fc, leftToCheck, endTime, isPastEndTime);
      if (getCacheSize(fc) > 0) {
        fc.decRef();
        continue;
      }
      // FileCache might be empty; see if we can remove it. "tryWriteLock"
      if (!fc.startEvicting()) continue;
      if (getCacheSize(fc) == 0) {
        fc.commitEvicting();
        iter.remove();
      } else {
        fc.abortEvicting();
      }
    }
  }
Class used to slowly clean up a map of FileCache-s.
llap-server/src/java/org/apache/hadoop/hive/llap/cache/FileCacheCleanupThread.java