private boolean lockFile(boolean shared) throws SecurityException {
  boolean usernode=isUserNode();
  int[] result;
  int errorCode=0;
  File lockFile=(usernode ? userLockFile : systemLockFile);
  long sleepTime=INIT_SLEEP_TIME;
  for (int i=0; i < MAX_ATTEMPTS; i++) {
    try {
      int perm=(usernode ? USER_READ_WRITE : USER_RW_ALL_READ);
      result=lockFile0(lockFile.getCanonicalPath(),perm,shared);
      errorCode=result[ERROR_CODE];
      if (result[LOCK_HANDLE] != 0) {
        if (usernode) {
          userRootLockHandle=result[LOCK_HANDLE];
        }
 else {
          systemRootLockHandle=result[LOCK_HANDLE];
        }
        return true;
      }
    }
 catch (    IOException e) {
    }
    try {
      Thread.sleep(sleepTime);
    }
 catch (    InterruptedException e) {
      checkLockFile0ErrorCode(errorCode);
      return false;
    }
    sleepTime*=2;
  }
  checkLockFile0ErrorCode(errorCode);
  return false;
}

private boolean lockFile ( boolean shared ) throws SecurityException { boolean usernode = isUserNode ( ) ; int [ ] result ; int errorCode = 0 ; File lockFile = ( usernode ? userLockFile : systemLockFile ) ; long sleepTime = INIT_SLEEP_TIME ; for ( int i = 0 ; i < MAX_ATTEMPTS ; i ++ ) { try { int perm = ( usernode ? USER_READ_WRITE : USER_RW_ALL_READ ) ; result = lockFile0 ( lockFile . getCanonicalPath ( ) , perm , shared ) ; errorCode = result [ ERROR_CODE ] ; if ( result [ LOCK_HANDLE ] != 0 ) { if ( usernode ) { userRootLockHandle = result [ LOCK_HANDLE ] ; } else { systemRootLockHandle = result [ LOCK_HANDLE ] ; } return true ; } } catch ( IOException e ) { } try { Thread . sleep ( sleepTime ) ; } catch ( InterruptedException e ) { checkLockFile0ErrorCode ( errorCode ) ; return false ; } sleepTime *= 2 ; } checkLockFile0ErrorCode ( errorCode ) ; return false ; }
try to acquire the appropriate file lock ( user or system ) . if the initial attempt fails , several more attempts are made using an exponential backoff strategy . if all attempts fail , this method returns false .
