日期:2014-05-16  浏览次数:20458 次

一个用于列举所有线程的JSP页面,便于调试(转载)

原帖地址http://www.oschina.net/code/snippet_12_2917

?

<html>
<head>
<title>Threads in oschina</title>
<style>
body {font-size:8pt;}
ol {line-height:18px;}
</style>
</head>
<body>
<strong>java.io.tmpdir:</strong>
<ul>
<li><%=System.getProperty("java.io.tmpdir")%></li>
</ul>
<br/>
<strong>Memory:</strong>
<ol>
<li>freeMemory=<%=Runtime.getRuntime().freeMemory()/(1024*1024)%>M</li>
<li>totalMemory=<%=Runtime.getRuntime().totalMemory()/(1024*1024)%>M</li>
<li>maxMemory=<%=Runtime.getRuntime().maxMemory()/(1024*1024)%>M</li>
</ol>
<br/>
<strong>Thread:</strong>
<ol>
<%for(Thread t : list_threads()){%>
<li><%=t.getName()%>(<b><%=t.getState()%></b>) : <%=t.getClass().getName()%></li>
<%}%>
</ol>
<%!
public static java.util.List<Thread> list_threads(){
int tc = Thread.activeCount();
Thread[] ts = new Thread[tc];
Thread.enumerate(ts);
return java.util.Arrays.asList(ts);
}
%>
</body>
</html>