Arc-04-08 JSP 页面查找 CPU 100% 堆栈
JSP 页面查找 CPU 100% 堆栈
<%@ 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 MAX_TIME=1000; final long THEAD_ID=1; final boolean IS_OUT_DETAIL=false; 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>=MAX_TIME || threadId ==THEAD_ID){ 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>"); if(IS_OUT_DETAIL){ out.println("<div>"+"Class:" + stackElements[s].getClassName()+"</div>"); out.println("<div>"+"File:" + stackElements[s].getFileName()+"</div>"); out.println("<div>"+"Line:" + stackElements[s].getLineNumber()+"</div>"); out.println("<div>"+"Method:" + stackElements[s].getMethodName()+"</div>"); out.println("<div>"+"-----------------------------------"+"</div>"); } } } out.println("</div>"); } } %> </body> </html>
相关推荐
omyrobin 2020-09-23
gocuber 2020-07-16
贤时间 2020-07-06
hickwu 2020-06-14
xushxbigbear微信 2020-06-12
shayuchaor 2020-06-07
乾坤一碼農 2020-05-19
平凡的程序员 2020-05-07
IT小牛的IT见解 2020-04-30
BlueSkyUSC 2020-03-22
淼寒儿 2020-03-12
范范 2020-02-26
渴望就奋力追寻 2020-01-28
alicelmx 2020-01-24
Joymine 2020-01-17
hitxueliang 2020-01-07
roseying 2019-12-28
cxcxrs 2019-12-21