All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.purej.vminspect.html.ThreadsMainView Maven / Gradle / Ivy

Go to download

An easy to use, feature-rich, JMX-based and embeddable Java VM monitoring tool with a web-based user-interface

There is a newer version: 2.1.1
Show newest version
// Copyright (c), 2013, adopus consulting GmbH Switzerland, all rights reserved.
package com.purej.vminspect.html;

import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.util.List;
import com.purej.vminspect.data.ThreadData;

/**
 * Displays a list of threads as a HTML table.
 *
 * @author Stefan Mueller
 */
public final class ThreadsMainView extends AbstractHtmlView {
  private final List _threads;

  /**
   * Creates a new instance of this view.
   */
  public ThreadsMainView(StringBuilder output, List threads) {
    super(output);
    _threads = threads;
  }

  @Override
  public void render() throws IOException {
    writeln("

" + img("icons/threads-24.png", "Threads") + " Threads

"); ThreadMXBean mxBean = ManagementFactory.getThreadMXBean(); writeln("
"); writeln("Total live threads: " + _threads.size() + " (peek: " + mxBean.getPeakThreadCount() + ")
"); writeln("Total started threads: " + mxBean.getTotalStartedThreadCount()); writeln("

"); CandyHtmlTable table = new CandyHtmlTable("Threads", "Thread", "Demon", "Priority", "State", "Executing Method", "CPU Time Ms", "User Time Ms"); for (ThreadData thread : _threads) { table.nextRowWithClz(thread.isDeadlocked() ? "Deadlock" : ""); table.addValue(htmlEncode(thread.getName())); table.addValueCenter(thread.isDaemon() ? "Yes" : "No"); table.addValueRight(formatNumber(thread.getPriority())); table.addValueCenter(img("bullets/" + getStateIcon(thread), String.valueOf(thread.getState()))); table.addValue(getExecutingMethodWithStacktrace(thread)); table.addValueRight(formatNumber(thread.getCpuTimeMillis())); table.addValueRight(formatNumber(thread.getUserTimeMillis())); } table.endTable(); writeln("
"); String threadsDumpParam = "page=threadsDump"; writeln("
" + lnk(threadsDumpParam, img("icons/text-16.png", "Dump threads as text") + " Dump threads as text")); writeln("
"); } private static String getExecutingMethodWithStacktrace(ThreadData thread) { if (thread.getStackTrace() != null && thread.getStackTrace().length > 0) { return tooltip(thread.getStackTrace()[0].toString(), thread.getStackTraceString()); } return ""; } private static String getStateIcon(ThreadData threadData) { switch (threadData.getState()) { case RUNNABLE: return "green.png"; case WAITING: return "yellow.png"; case TIMED_WAITING: return "yellow.png"; case BLOCKED: return "red.png"; default: return "gray.png"; } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy