code: private synchronized boolean getServerLock() {
  
          Boolean fileExists = Boolean.FALSE;
          final File sDir = lockFile;
          try {
              fileExists = AccessController.doPrivileged(new java.security.PrivilegedExceptionAction<Boolean>() {
                  @Override
                  public Boolean run() throws Exception {
                      if (!sDir.exists()) {
                          return Boolean.FALSE;
                      }
                      return Boolean.TRUE;
                  }
              });
          } catch (Exception ex) {
              // Oh well.
          }
          if (!(fileExists.booleanValue()))
              return false;
  
          // Change to the "locking" state
          FileOutputStream fos = null;
          FileChannel fc = null;
          try {
              fos = new FileOutputStream(lockFile);
              fc = fos.getChannel();
              lockFileChannel = fc;
  
              // Try for a short period of time to obtain the lock
              // (if status mechanisms temporarily grab the file, we want to wait
              // to try to grab it.. )
              for (int i = 0; i < BootstrapConstants.MAX_POLL_ATTEMPTS; i++) {
                  serverLock = fc.tryLock();
                  if (serverLock != null) {
                      break;
                  } else {
                      try {
                          Thread.sleep(BootstrapConstants.POLL_INTERVAL_MS);
                      } catch (InterruptedException e) {
                      }
                  }
              }
          } catch (OverlappingFileLockException e) {
              // If we encounter an exception obtaining the lock, we can try
              // try closing the the relevant streams (channel first)
              if (!Utils.tryToClose(fc))
                  Utils.tryToClose(fos);
          } catch (IOException e) {
              // If we encounter an exception obtaining the lock, we can try
              // try closing the the relevant streams (channel first)
              if (!Utils.tryToClose(fc)) // try to close the wrapping-channel first.
                  Utils.tryToClose(fos);
          }
  
          return serverLock != null && serverLock.isValid();
      }
docs: Try to obtain server lock
  
  @return true if server lock was obtained (!null & valid)