Пример #1
0
  private int printThreadGroup(OutputSink out, ThreadGroupReference tg, int iThread) {
    out.println("Group " + tg.name() + ":");
    List<ThreadReference> tlist = tg.threads();
    int maxId = 0;
    int maxName = 0;
    for (int i = 0; i < tlist.size(); i++) {
      ThreadReference thr = tlist.get(i);
      int len = Utils.description(thr).length();
      if (len > maxId) {
        maxId = len;
      }
      String name = thr.name();
      int iDot = name.lastIndexOf('.');
      if (iDot >= 0 && name.length() > iDot) {
        name = name.substring(iDot + 1);
      }
      if (name.length() > maxName) {
        maxName = name.length();
      }
    }
    String maxNumString = String.valueOf(iThread + tlist.size());
    int maxNumDigits = maxNumString.length();
    for (int i = 0; i < tlist.size(); i++) {
      ThreadReference thr = tlist.get(i);
      char buf[] = new char[80];
      for (int j = 0; j < 79; j++) {
        buf[j] = ' ';
      }
      buf[79] = '\0';
      StringBuffer sbOut = new StringBuffer();
      sbOut.append(buf);

      // Right-justify the thread number at start of output string
      String numString = String.valueOf(iThread + i + 1);
      sbOut.insert(maxNumDigits - numString.length(), numString);
      sbOut.insert(maxNumDigits, ".");

      int iBuf = maxNumDigits + 2;
      sbOut.insert(iBuf, Utils.description(thr));
      iBuf += maxId + 1;
      String name = thr.name();
      int iDot = name.lastIndexOf('.');
      if (iDot >= 0 && name.length() > iDot) {
        name = name.substring(iDot + 1);
      }
      sbOut.insert(iBuf, name);
      iBuf += maxName + 1;
      sbOut.insert(iBuf, Utils.getStatus(thr));
      sbOut.setLength(79);
      out.println(sbOut.toString());
    }
    for (ThreadGroupReference tg0 : tg.threadGroups()) {
      if (!tg.equals(tg0)) { // TODO ref mgt
        iThread += printThreadGroup(out, tg0, iThread + tlist.size());
      }
    }
    return tlist.size();
  }
Пример #2
0
  private boolean doLoad(boolean suspended, StringTokenizer t) throws NoSessionException {

    String clname;

    if (!t.hasMoreTokens()) {
      clname = context.getMainClassName();
      if (!clname.equals("")) {
        // Run from prevously-set class name.
        try {
          String vmArgs = context.getVmArguments();
          runtime.run(suspended, vmArgs, clname, context.getProgramArguments());
          return true;
        } catch (VMLaunchFailureException e) {
          env.failure("Attempt to launch main class \"" + clname + "\" failed.");
        }
      } else {
        env.failure("No main class specifed and no current default defined.");
      }
    } else {
      clname = t.nextToken();
      StringBuffer sbuf = new StringBuffer();
      // Allow VM arguments to be specified here?
      while (t.hasMoreTokens()) {
        String tok = t.nextToken();
        sbuf.append(tok);
        if (t.hasMoreTokens()) {
          sbuf.append(' ');
        }
      }
      String args = sbuf.toString();
      try {
        String vmArgs = context.getVmArguments();
        runtime.run(suspended, vmArgs, clname, args);
        context.setMainClassName(clname);
        // context.setVmArguments(vmArgs);
        context.setProgramArguments(args);
        return true;
      } catch (VMLaunchFailureException e) {
        env.failure("Attempt to launch main class \"" + clname + "\" failed.");
      }
    }
    return false;
  }