在实际的项目中我们通过Thread.getAllStacktraces()方法进行查看相关的信息。这样可以随时方便的管理查看程序中的线程的相关信息
<%@ page language="java" contentType="text/html; charset=utf-8"
import="java.util.Map"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>服务器线程</title>
</head>
<body>
<pre>
<%
for (Map.Entry<Thread, StackTraceElement[]> strack :Thread.getAllStackTraces().entrySet()) {
Thread thread = strack.getKey();
StackTraceElement[] se = strack.getValue();
if(thread.equals(Thread.currentThread())) {
continue;
}
out.print("\n线程:" + thread.getName() + "\n");
for(StackTraceElement ele: se) {
out.print("\t" + ele + "\n");
}
}
%>
</pre>
</body>
</html>