public void logTraces(final boolean toStdout, final Thread targetThread, final int interval,
      final AtomicBoolean done) {
    if (targetThread == null) {
      return;
    }
    Thread watcherThread =
        new LoggingThread("Stack Tracer for '" + targetThread.getName() + "'", false, () -> {
          while (!done.get()) {
            try {
              Thread.sleep(500);
            } catch (InterruptedException e) {
              return;
            }
            if (!done.get() && targetThread.isAlive()) {
              StringBuilder sb = new StringBuilder(500);
              if (toStdout) {
                sb.append("[trace ").append(getTimeStamp()).append("] ");
              }
              StackTraceElement[] els = targetThread.getStackTrace();
              sb.append("Stack trace for '").append(targetThread).append("'")
                  .append(lineSeparator());
              if (els.length > 0) {
                for (final StackTraceElement el : els) {
                  sb.append("\tat ").append(el).append(lineSeparator());
                }
              } else {
                sb.append("    no stack").append(lineSeparator());
              }
              if (toStdout) {
                System.out.println(sb);
              } else {
                info(sb.toString());
              }
            }
          }
        });
    watcherThread.start();
  }
Utility to periodically log a stack trace for a thread. The thread should be alive when this
method is invoked.

@param toStdout whether to log to stdout or to this log writer
@param targetThread the thread to snapshot
@param interval millis to wait betweeen snaps
@param done when to stop snapshotting (also ceases if targetThread dies)
geode-core/src/main/java/org/apache/geode/internal/logging/LogWriterImpl.java