src/main/java/org/apache/hadoop/hdfs/server/namenode/analytics/web/NamenodeAnalyticsMethods.java
@GET
  @Path("/threads")
  @Produces({MediaType.TEXT_PLAIN})
  public Response threads() {
    try {
      before();
      StringWriter writer = new StringWriter();
      ThreadMXBean tb = ManagementFactory.getThreadMXBean();
      int threadsNew = 0;
      int threadsRunnable = 0;
      int threadsBlocked = 0;
      int threadsWaiting = 0;
      int threadsTimedWaiting = 0;
      int threadsTerminated = 0;
      long[] threadIds = tb.getAllThreadIds();
      for (ThreadInfo threadInfo : tb.getThreadInfo(threadIds, 0)) {
        if (threadInfo == null) {
          continue; // race protection
        }
        switch (threadInfo.getThreadState()) {
          case NEW:
            threadsNew++;
            break;
          case RUNNABLE:
            threadsRunnable++;
            break;
          case BLOCKED:
            threadsBlocked++;
            break;
          case WAITING:
            threadsWaiting++;
            break;
          case TIMED_WAITING:
            threadsTimedWaiting++;
            break;
          case TERMINATED:
            threadsTerminated++;
            break;
          default:
            break;
        }
      }
      writer.write(
          "New Threads: "
              + threadsNew
              + "\n"
              + "Runnable Threads: "
              + threadsRunnable
              + "\n"
              + "Blocked Threads: "
              + threadsBlocked
              + "\n"
              + "Waiting Threads: "
              + threadsWaiting
              + "\n"
              + "Timed-Waiting Threads: "
              + threadsTimedWaiting
              + "\n"
              + "Terminated Threads: "
              + threadsTerminated
              + "\n");
      return Response.ok(writer.toString(), MediaType.TEXT_PLAIN).build();
    } catch (Exception ex) {
      return handleException(ex);
    } finally {
      after();
    }
  }
/**
   * THREADS endpoint is meant to show the thread information about the NNA instance in PLAINTEXT
   * form. TODO: Convert the output to JSON form.
   */
THREADS endpoint is meant to show the thread information about the NNA instance in PLAINTEXT
form. TODO: Convert the output to JSON form.
THREADS endpoint is meant to show the thread information about the NNA instance in PLAINTEXT form . TODO : Convert the output to JSON form .
@GET
  @Path("/threads")
  @Produces({MediaType.TEXT_PLAIN})
  public Response threads() {
    try {
      before();
      StringWriter writer = new StringWriter();
      ThreadMXBean tb = ManagementFactory.getThreadMXBean();
      int threadsNew = 0;
      int threadsRunnable = 0;
      int threadsBlocked = 0;
      int threadsWaiting = 0;
      int threadsTimedWaiting = 0;
      int threadsTerminated = 0;
      long[] threadIds = tb.getAllThreadIds();
      for (ThreadInfo threadInfo : tb.getThreadInfo(threadIds, 0)) {
        if (threadInfo == null) {
          continue; 
        }
        switch (threadInfo.getThreadState()) {
          case NEW:
            threadsNew++;
            break;
          case RUNNABLE:
            threadsRunnable++;
            break;
          case BLOCKED:
            threadsBlocked++;
            break;
          case WAITING:
            threadsWaiting++;
            break;
          case TIMED_WAITING:
            threadsTimedWaiting++;
            break;
          case TERMINATED:
            threadsTerminated++;
            break;
          default:
            break;
        }
      }
      writer.write(
          "New Threads: "
              + threadsNew
              + "\n"
              + "Runnable Threads: "
              + threadsRunnable
              + "\n"
              + "Blocked Threads: "
              + threadsBlocked
              + "\n"
              + "Waiting Threads: "
              + threadsWaiting
              + "\n"
              + "Timed-Waiting Threads: "
              + threadsTimedWaiting
              + "\n"
              + "Terminated Threads: "
              + threadsTerminated
              + "\n");
      return Response.ok(writer.toString(), MediaType.TEXT_PLAIN).build();
    } catch (Exception ex) {
      return handleException(ex);
    } finally {
      after();
    }
  }
@ GET @ Path ( "/threads" ) @ Produces ( { MediaType . TEXT_PLAIN } ) public Response threads ( ) { try { before ( ) ; StringWriter writer = new StringWriter ( ) ; ThreadMXBean tb = ManagementFactory . getThreadMXBean ( ) ; int threadsNew = 0 ; int threadsRunnable = 0 ; int threadsBlocked = 0 ; int threadsWaiting = 0 ; int threadsTimedWaiting = 0 ; int threadsTerminated = 0 ; long [ ] threadIds = tb . getAllThreadIds ( ) ; for ( ThreadInfo threadInfo : tb . getThreadInfo ( threadIds , 0 ) ) { if ( threadInfo == null ) { continue ; } switch ( threadInfo . getThreadState ( ) ) { case NEW : threadsNew ++ ; break ; case RUNNABLE : threadsRunnable ++ ; break ; case BLOCKED : threadsBlocked ++ ; break ; case WAITING : threadsWaiting ++ ; break ; case TIMED_WAITING : threadsTimedWaiting ++ ; break ; case TERMINATED : threadsTerminated ++ ; break ; default : break ; } } writer . write ( "New Threads: " + threadsNew + "\n" + "Runnable Threads: " + threadsRunnable + "\n" + "Blocked Threads: " + threadsBlocked + "\n" + "Waiting Threads: " + threadsWaiting + "\n" + "Timed-Waiting Threads: " + threadsTimedWaiting + "\n" + "Terminated Threads: " + threadsTerminated + "\n" ) ; return Response . ok ( writer . toString ( ) , MediaType . TEXT_PLAIN ) . build ( ) ; } catch ( Exception ex ) { return handleException ( ex ) ; } finally { after ( ) ; } }
THREADS endpoint is meant to show the thread information about the NNA instance in PLAINTEXT
 form.
THREADS endpoint is meant to show the thread information about the NNA instance in PLAINTEXT form .
// race protection