方便查看线程状况的jsp页面

此方法来自深入理解java虚拟机一书,用作管理员页面,可以随时用浏览器查看线程堆栈

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<html>
  <head>
    <title>服务器线程信息</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
  </head>
  
  <body>
    <pre>
        <%
            for(Map.Entry<Thread,StackTraceElement[]> stackTrace : Thread.getAllStackTraces().entrySet()){
                Thread thread = (Thread)stackTrace.getKey();
                StackTraceElement[] stack = (StackTraceElement[])stackTrace.getValue();
                if(thread.equals(Thread.currentThread())){
                    continue;
                }
                out.print("
线程:"+thread.getName()+"
");
                for(StackTraceElement element : stack){
                    out.print("	"+element+"
");
                }
            }
         %>
    </pre>
  </body>
</html>
原文地址:https://www.cnblogs.com/by-dxm/p/8706982.html