方便查看线程状况的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("\n线程:"+thread.getName()+"\n"); for(StackTraceElement element : stack){ out.print("\t"+element+"\n"); } } %> </pre> </body> </html>
本博客作为一个入门者的自学记录,欢迎各位同行者不吝赐教。