public void obtain(long timeout_ms) throws IOException, InterruptedException, TimeoutException {
  Long quit_time=System.currentTimeMillis() + timeout_ms;
  if (fileLock != null && fileLock.isValid()) {
    return;
  }
  do {
    try {
      fileLock=fileToLock.tryLock();
      return;
    }
 catch (    OverlappingFileLockException e) {
      Thread.sleep(1000);
    }
  }
 while (System.currentTimeMillis() < quit_time);
  throw new TimeoutException();
}

public void obtain ( long timeout_ms ) throws IOException , InterruptedException , TimeoutException { Long quit_time = System . currentTimeMillis ( ) + timeout_ms ; if ( fileLock != null && fileLock . isValid ( ) ) { return ; } do { try { fileLock = fileToLock . tryLock ( ) ; return ; } catch ( OverlappingFileLockException e ) { Thread . sleep ( 1000 ) ; } } while ( System . currentTimeMillis ( ) < quit_time ) ; throw new TimeoutException ( ) ; }
locks the file , with a timeout ( non - blocking ) .
