code: public void lock() throws FileLockException, IOException {
          if (mode == AccessMode.READ_ONLY) {
              return;
          }
  
          for (int retries = 0; retries < max_retries_connect; retries++) {
              try {
                  fileLock = channel.lock();
                  break; // the lock was succesful
              } catch (OverlappingFileLockException e) {
                  try {
                      logger.debug("Can't open file '" + osFile.getAbsolutePath()
                              + "' because it's locked. Waiting {} ms and retry {}", RETRY_CONNECT_WAITTIME,
                              retries);
                      System.runFinalization(); // FORCE FINALIZATION TO COLLECT ALL THE PENDING BUFFERS
                      Thread.sleep(RETRY_CONNECT_WAITTIME);
                  } catch (InterruptedException ex) {
                      // will throw a FileLockException further
                  }
              }
          }
  
          if (fileLock == null) {
              this.close();
              throw new FileLockException("File " + osFile.getPath()
                      + " is locked by another process, maybe the database is in use by another process.");
          }
      }
docs: tries to lock the file
  
  @throws FileLockException
  @throws IOException