public boolean tryLock() throws IOException {
    synchronized (this) {
      // trace("Acquiring lock on " + file.getAbsolutePath)
      try {
        // weirdly this method will return null if the lock is held by another
        // process, but will throw an exception if the lock is held by this process
        // so we have to handle both cases
        flock = channel.tryLock();
        return flock != null;
      } catch (OverlappingFileLockException e) {
        return false;
      }
    }
  }
Try to lock the file and return true if the locking succeeds
ambry-utils/src/main/java/com/github/ambry/utils/FileLock.java