在tomcat服务器上运行的J2ee线程

时间:2014-02-05 07:40:04

标签: java tomcat

如何查找在tomcat服务器上运行的线程数?

如果有人知道答案,请告诉你。

2 个答案:

答案 0 :(得分:1)

使用jconsole <process-id>将探查器附加到tomcat,它将显示线程和内存的详细级别详细信息。

jps命令将显示正在运行的所有java进程。找到tomcat的进程ID并在jconsole中提供<​​/ p>

JConsole

enter image description here

答案 1 :(得分:0)

当我无法使用JConsole或VVM时,我通常上传一个简单的JSP来显示信息 在这个web中,您可以找到一些JSP示例来执行此操作。我通常使用这个:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.io.PrintStream,
                 java.lang.management.ManagementFactory,
                 java.lang.management.ThreadInfo,
                 java.lang.management.ThreadMXBean"%>
<!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>Quick and Dirty JSP Thread Report</title>
</head>
<body>
<%!
private static ThreadMXBean thMxBean = 
ManagementFactory.getThreadMXBean();
private static String getTaskName(long id, String name) {
    if (name == null) {
        return Long.toString(id);
    }
    return id + " (" + name + ")<br>";
}
%><%
final int STACK_DEPTH = 20;
boolean contention = thMxBean.isThreadContentionMonitoringEnabled();
long[] threadIds = thMxBean.getAllThreadIds();

out.println("Process Thread Dump: <br/>");
out.println(threadIds.length + " active threads<br/>");
for (long tid : threadIds) {
    ThreadInfo info = thMxBean.getThreadInfo(tid, STACK_DEPTH);
    if (info == null) {
        out.println("  Inactive");
        continue;
    }
    out.println(" <br/><br/>Thread "
            + getTaskName(info.getThreadId(), info.getThreadName()));
    Thread.State state = info.getThreadState();
    out.println("  State: " + state);
    out.println("  <br/>Blocked count: " + info.getBlockedCount());
    out.println("  <br/>Waited count: " + info.getWaitedCount());
    if (contention) {
        out.println("  <br/>Blocked time: " + info.getBlockedTime());
        out.println(" <br/> Waited time: " + info.getWaitedTime());
    }
    if (state == Thread.State.WAITING) {
        out.println("  Waiting on " + info.getLockName());
    } else if (state == Thread.State.BLOCKED) {
        out.println("  Blocked on " + info.getLockName());
        out.println("  Blocked by <br/>"
                + getTaskName(info.getLockOwnerId(),
                        info.getLockOwnerName()));
    }
    out.println("  <br/>Stack: ");
    for (StackTraceElement frame : info.getStackTrace()) {
        out.println("    " + frame.toString());
    }
}%>

我希望这会有所帮助。