arc-04-09-简单的性能调优

<%@ page contentType="text/html;charset=gb2312"%> 
<%@ page import="java.io.*,
                 java.util.*,
                 java.net.*,
                 java.lang.management.*"
                 
%>
<html>
<head>
    <title>DeProfile</title>
  <style type="text/css">
			body{font-size:14px;font-family:Arial;}
			.stack{font-size:12px; font-family:Arial; margin:10px}
  </style>
</head>
<body>
<%
final long DEFAULT_MAX_TIME=1000;
final long DEFAULT_THEAD_ID=0;

/* Get parameter*/
Long overtime =Long.parseLong(request.getParameter("t")==null?"0":request.getParameter("t"));//.getAttribute("t");
Long theadid =Long.parseLong(request.getParameter("i")==null?"0":request.getParameter("i"));//(Long)request.getAttribute("i");
if(overtime==null || overtime<=0){
	overtime =DEFAULT_MAX_TIME;
}
if(theadid==null || theadid<=0){
	theadid =DEFAULT_THEAD_ID;
}
%>

<form action="" method="POST">
<table cellpadding="0">
<tr>
<td><input type="hidden" name="dir" value="<%=request.getAttribute("dir")%>">
<input type="file" name="myFile"></td>
<td><input type="Submit" class="button" name="Submit" value="上传"></td>
</tr>
</table>
</form>


<%
ThreadMXBean tm = ManagementFactory.getThreadMXBean();
tm.setThreadContentionMonitoringEnabled(true);
long [] tid = tm.getAllThreadIds();
ThreadInfo [] tia = tm.getThreadInfo(tid, Integer.MAX_VALUE);

for (int i = tia.length-1; i > 0; i--) {
long threadId = tia[i].getThreadId();
long cpuTime = tm.getThreadCpuTime(tia[i].getThreadId())/(1000*1000*1000);
out.println("<div>ThreadId:"+threadId+" CPU Time:"+cpuTime+"</div>");
if(cpuTime >= overtime || threadId ==theadid){
out.println("<div>"+"==================================================================="+"</div>");  
out.println("<div class=stack>");
out.println("<div>Stack Info - Thread ID: "+threadId+"</div>");
StackTraceElement[] stackElements = tia[i].getStackTrace();  
if (stackElements != null) {  
    for (int s = 0; s < stackElements.length; s++) {  
      out.println("<div>"+"" + stackElements[s]+"</div>");  
    }  
}  
out.println("</div>");

}
}
%>

</body>
</html>
 

访问http://localhost/deprofiler.jsp?t=10

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值