private static void setCrumbInThread(Thread t, CrumbType type, Object crumb) {

    int typeIndex = type.ordinal();
    String name = t.getName();
    String crumbString;

    if (crumb == null) {
      crumbString = ""; // remove existing crumb, if any
    } else {
      crumbString = crumbStarts[typeIndex] + crumb + crumbEnds[typeIndex];
    }

    int startIndex = name.indexOf(crumbStarts[typeIndex]);
    int endIndex = -1;

    if (startIndex < 0) {
      // there may be a higher numbered breadcrumb already in the thread name
      for (int i = typeIndex + 1; (startIndex < 0) && (i <= Crumbiest.ordinal()); i++) {
        startIndex = name.indexOf(crumbStarts[i]);
        if (startIndex >= 0) {
          endIndex = name.indexOf(crumbEnds[i], startIndex + 1);
        }
      }
    }

    if (startIndex < 0) {
      // no equal or higher numbered breadcrumbs - just tack this
      // one onto the end of the thread's name
      t.setName(name + crumbString);
    } else if (endIndex > 0) {
      // insert before the higher-numbered breadcrumb
      t.setName(
          name.substring(0, startIndex) + crumbString + name.substring(startIndex));
    } else {
      // replace the existing breadcrumb
      endIndex = name.indexOf(crumbEnds[typeIndex], startIndex + 1);

      // this shouldn't happen
      assert endIndex > 0 : "odd thread name: " + name;

      t.setName(name.substring(0, startIndex) + crumbString
          + name.substring(endIndex + crumbEnds[typeIndex].length()));
    }
  }
This method does all of the work of setting/clearing individual breadcrumbs in thread names

@param t the thread to modify
@param type the type of breadcrumb
@param crumb the crumb to insert, or null to clear
geode-core/src/main/java/org/apache/geode/internal/util/Breadcrumbs.java