public synchronized boolean tryLock() {
        LOGGER.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;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
Try to lock the file and return true if the locking succeeds
server-common/src/main/java/org/apache/kafka/server/util/FileLock.java