ThreadMXBean定位CPU占用过高JSP

使用该JSP页面即可打印出虚拟机当前进程所执行的代码,该代码来自新浪云。
<%@page import="java.util.ArrayList"%>
<%@page import="java.lang.management.ThreadInfo"%>
<%-- <%@page import="com.sina.sae.util.SaeUserInfo"%> --%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Arrays"%>
<%@page import="java.lang.management.ThreadMXBean"%>
<%@page import="java.lang.management.CompilationMXBean"%>
<%@page import="java.lang.management.OperatingSystemMXBean"%>
<%@page import="java.lang.management.GarbageCollectorMXBean"%>
<%@page import="java.util.List"%>
<%@page import="java.lang.management.MemoryUsage"%>
<%@page import="java.lang.management.MemoryMXBean"%>
<%@page import="java.lang.management.ClassLoadingMXBean"%>
<%@page import="java.lang.management.RuntimeMXBean"%>
<%@page import="java.lang.management.ManagementFactory"%>
<%@page import="java.util.Date"%>
<%@ page language="java"   pageEncoding="utf-8"%>




Sina App Engine Java








<%
	RuntimeMXBean rMXBean = ManagementFactory.getRuntimeMXBean();
	ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
	List aGCMXBeans = ManagementFactory.getGarbageCollectorMXBeans();
	
	String [] node = rMXBean.getName().split("@");//节点名称
 	String nodename = node[node.length-1];
 	String currentNode = nodename+request.getLocalPort();
	long cputime = threadMXBean.getCurrentThreadCpuTime()/1000000;//cpu时间
	long livethread = threadMXBean.getThreadCount();//活动线程数
	long topthread = threadMXBean.getPeakThreadCount();//峰值线程数
	long deamonthread = threadMXBean.getDaemonThreadCount();//守护线程数
	long totalthread = threadMXBean.getTotalStartedThreadCount();//创建线程总数
	long [] ids = threadMXBean.getAllThreadIds();//所有线程ID号
	//计算各类状态线程数量
	long newcount=0,runcount=0,blockedcount=0,waitingcount=0,twaitcount=0,terminatedcount=0;
	List threads = new ArrayList(); 
	for(int i=0;i



	

<%-- Threads - <%=SaeUserInfo.getAppName() %> --%> Refresh All 

节点名称: <%=nodename %>                  线程CPU时间: <%=cputime %> ms


Overview

创建线程总数: <%=totalthread %>            活动线程数: <%=livethread %>                  峰值线程数:<%=topthread %>                  守护线程数: <%=deamonthread %>

NEW 线程: <%=newcount %>                  RUNNABLE 线程: <%=runcount %>                  BLOCKED 线程: <%=blockedcount %>                  WATTING 线程: <%=waitingcount %>                  TIMED_WATTING 线程: <%=twaitcount %>                  TERMINATED 线程: <%=terminatedcount %>


<% String color =""; for(int i=0;i <%if(i==0) {%> <% }%> <% } %>
  Thread Name  Thread Info
 <%=threadName %>

请求节点:  <%=node[node.length-1] %>

线程名称:  <%= threadInfo.getThreadName()%>

线程状态:  <%=threadInfo.getThreadState() %>        CPU时间: <%=threadMXBean.getThreadCpuTime(threadInfo.getThreadId())/(1000*1000) %> ms        阻塞总数:  <%= threadInfo.getBlockedCount()%>        等待总数:  <%= threadInfo.getWaitedCount()%>

堆栈跟踪:  

<% for (StackTraceElement e : threadInfo.getStackTrace()){%>  <%=e.toString()+"
" %> <%} %>


ThreadMXBean定位CPU占用过高JSP_第1张图片

你可能感兴趣的:(ThreadMXBean定位CPU占用过高JSP)