public long cleanupResourceLocks(long timeout) {
    long removed = 0L;
    final long currentTime = System.currentTimeMillis();
    for (Iterator<Map.Entry<String, ResourceLock>> it = locks.entrySet().iterator(); it.hasNext();) {
      final ResourceLock resourceLock = it.next().getValue();
      if (currentTime - resourceLock.lastHeartBeatTime.get() > timeout) {
        if (resourceLock.state.compareAndSet(State.ACQUIRED, State.EXPIRED)) {
          it.remove();
          removed++;
        }
      }
    }
    return removed;
  }
Method that removes from the handler those locks that have expired.
@param timeout time after which we consider the locks to have expired
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MaterializationsRebuildLockHandler.java