<%@ page contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%> <%@ page import="java.lang.management.ManagementFactory, java.lang.management.ThreadMXBean, java.lang.management.ThreadInfo, java.io.IOException"%> <%@include file="header.jsp" %> <%! static ThreadMXBean tmbean = ManagementFactory.getThreadMXBean(); %>

Thread Dump

<% out.print(System.getProperty("java.vm.name") + " " + System.getProperty("java.vm.version") + "
"); %>
<% long[] tids; ThreadInfo[] tinfos; out.print("Thread Count: current=" + tmbean.getThreadCount() + " deamon=" + tmbean.getDaemonThreadCount() + " peak=" + tmbean.getPeakThreadCount()); %>
<% tids = tmbean.findMonitorDeadlockedThreads(); if (tids == null) { out.print("No deadlock found."); } else { out.print("Deadlock found :-"); tinfos = tmbean.getThreadInfo(tids, Integer.MAX_VALUE); for (ThreadInfo ti : tinfos) { printThreadInfo(ti, out); } } %>
<% out.print("Full Thread Dump:
"); tids = tmbean.getAllThreadIds(); tinfos = tmbean.getThreadInfo(tids, Integer.MAX_VALUE); for (ThreadInfo ti : tinfos) { printThreadInfo(ti, out); } %>


Return to Admin Page <%! static String INDENT = "     "; static void printThreadInfo(ThreadInfo ti, JspWriter out) throws IOException { long tid = ti.getThreadId(); StringBuilder sb = new StringBuilder("\"" + ti.getThreadName() + "\"" + " Id=" + tid + " in " + ti.getThreadState()); if (ti.getLockName() != null) { sb.append(" on lock=" + ti.getLockName()); } if (ti.isSuspended()) { sb.append(" (suspended)"); } if (ti.isInNative()) { sb.append(" (running in native)"); } if (tmbean.isThreadCpuTimeSupported()) { sb.append(" total cpu time=" +formatNanos(tmbean.getThreadCpuTime(tid))); sb.append(" user time=" +formatNanos(tmbean.getThreadUserTime(tid))); } out.print(sb.toString()+"
"); if (ti.getLockOwnerName() != null) { out.print(INDENT + " owned by " + ti.getLockOwnerName() + " Id=" + ti.getLockOwnerId()+"
"); } for (StackTraceElement ste : ti.getStackTrace()) { out.print(INDENT + "at " + ste.toString()+"
"); } out.print("
"); } static String formatNanos(long ns) { return String.format("%.4fms", ns / (double) 1000000); } %>