public void run() {
      int i;
      String cmdToLookFor = getServerProperty("pidHint");
      if (cmdToLookFor == null) {
        StringBuffer buf = new StringBuffer();
        for (i = 0; i < mExecArgs.length; i++) {
          if (i > 0) {
            buf.append(" ");
          }
          buf.append(mExecArgs[i]);
        }
        cmdToLookFor = buf.toString();
      }

      mLogger.finer("Looking for pid for command: " + cmdToLookFor);

      i = 0;
      do {
        try {
          Thread.sleep(1000);
        } catch (InterruptedException ie) {
        }
        mPid = UnixStdlib.getProcessID(cmdToLookFor);
      } while (mPid == 0 && ++i < 300); // up to 5 minutes

      if (mPid == 0) {
        mLogger.warning("Giving up on trying to identify pid");
      } else {
        mLogger.finer("Serverpid server=" + mName + " pid=" + mPid);
      }
    }
  protected void prepare() throws Exception {
    try {

      List execCommand = buildExecCommand();

      if (execCommand == null) {
        mLogger.severe("No command property was specified; disabling server");
        synchronized (this) {
          changeState(STATE_DISABLED);
        }
        return;
      } else {
        mExecArgs = (String[]) execCommand.toArray(new String[0]);
        StringBuffer printableCmd = new StringBuffer(4096);
        int index = 0;
        for (; index < mExecArgs.length - 1; index++) {
          printableCmd.append(mExecArgs[index]).append(" ");
        }
        printableCmd.append(mExecArgs[index]);
        mPrintableCommand = printableCmd.toString();

        if (useOptimizeIt()) {
          System.err.println(mPrintableCommand);
        }
      }
    } catch (Exception ex) {
      mLogger.severe("Failed In preparing execargs");
      throw ex;
    }
  }
  /**
   * Looks for properties "watchdog.server.&lt;SERVER_NAME&gt;.java.flags" followed by
   * "watchdog.java.flags" in the configuration and returns the first non-null value. If both are
   * not available, returns an empty list.
   */
  protected List getJVMFlags() {
    String servJVMFlags = getProperty(mPropertyPrefix + ".java.flags");
    String wdJVMFlags = getProperty(WDConstants.WD_PREFIX + ".java.flags");

    StringBuffer sb = new StringBuffer();
    if (wdJVMFlags != null) sb.append(wdJVMFlags);
    if (servJVMFlags != null) sb.append(servJVMFlags);

    String javaFlags = sb.toString();

    String debugFlags = getJVMDebugFlags();
    if (debugFlags == null) debugFlags = "";

    javaFlags = debugFlags + " " + javaFlags;
    javaFlags = javaFlags.trim();

    if (javaFlags.equals("")) {
      return new LinkedList();
    }

    return tokenizeCommand(javaFlags);
  }
  /**
   * Tokenizes a command string into a list.
   *
   * @throws Exception if the command cannot be tokenized
   */
  protected static LinkedList _tokenizeCommand(String cmd) throws Exception {

    LinkedList tokens = new LinkedList();
    int startIndex = 0;
    int dQuoteAt = cmd.indexOf('"');
    int sQuoteAt = cmd.indexOf('\'');

    if (dQuoteAt == -1 && sQuoteAt == -1) {
      StringTokenizer st = new StringTokenizer(cmd.trim());
      while (st.hasMoreTokens()) {
        tokens.add(st.nextToken());
      }
      return tokens;
    }

    char[] chArray = cmd.trim().toCharArray();

    int endIndex = 0;
    boolean inQuotes = false;
    char c = 0;
    char lastc = 0;
    char lastqc = 0;
    StringBuffer sb = new StringBuffer(80);

    while (endIndex < chArray.length) {
      c = chArray[endIndex];
      if (!Character.isWhitespace(c)) {
        if (c == '"' || c == '\'') {
          if (inQuotes && lastc != '\\' && lastqc == c) {
            tokens.add(sb.toString());
            inQuotes = false;
            sb.setLength(0);
          } else if (!inQuotes) {
            inQuotes = true;
            lastqc = c;
          } else {
            sb.append(c);
          }
        } else if (c == '\\') {
          if (lastc == '\\') sb.append(c);
        } else {
          sb.append(c);
        }
      } else {
        if (inQuotes) {
          sb.append(c);
        } else {
          if (sb.length() > 0) {
            tokens.add(sb.toString());
            sb.setLength(0);
          }
        }
      }
      lastc = c;
      ++endIndex;
    }

    if (inQuotes) {
      throw new Exception(
          WDExUtil.formatMessage(WDExConstants.UNTERMINATED_STRING, WDUtil.toArray(cmd)));
    }
    return tokens;
  }