Over a million developers have joined DZone.

Embed Thread Dump Tool Using JSP In Your Enterprise J2EE Application

·
// Following is the content of a JSP which can be added in J2EE application to get thread dump using a browser. Save it as stack.jsp in war file and also add appropriate protection


<%@ page language="java" import="java.util.*,java.lang.Thread.State" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>




Thread Dump


<% 
	out.print("Generating Thread-dump at:" + (new java.util.Date()).toString() + "
"); out.println("----------------------------
"); Map map = Thread.getAllStackTraces(); Iterator itr = map.keySet().iterator(); while (itr.hasNext()) { Thread t = itr.next(); StackTraceElement[] elem = map.get(t); out.print("\"" + t.getName() + "\""); out.print(" prio=" + t.getPriority()); out.print(" tid=" + t.getId()); State s = t.getState(); String state = null; String color = "000000"; String GREEN = "00FF00"; String RED = "FF0000"; String ORANGE = "FCA742"; switch(s) { case NEW: state ="NEW"; color = GREEN; break; case BLOCKED: state = "BLOCKED"; color = RED; break; case RUNNABLE: state = "RUNNABLE"; color = GREEN; break; case TERMINATED: state = "TERMINATED"; break; case TIMED_WAITING: state = "TIME WAITING"; color = ORANGE; break; case WAITING: state = "WAITING"; color = RED; break; } out.print(" @@@@"); out.println(" " + state + "
"); for (int i=0; i < elem.length; i++) { out.println(" at "); out.print(elem[i].toString()); out.println("
"); } out.println("----------------------------
"); } %>
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}