- 浏览: 191375 次
- 性别:
- 来自: 广州
最新评论
-
MayBe_you:
...
java重构文档(改造bad smell) -
原水小子:
我下载安装完打开后还是英文版的~
JSmooth 0.9.9-7 汉化版 发布(图文) 地址已修正 -
sornor:
还是不行啊!!
mysql控制台显示乱码问题
ThreadDump对于JVM诊断和调优是个好东西. 以前, 我们生成ThreadDump, 一般都需要另外连到服务器上的进程管理器才行, 不管是Ctrl+Break还是kill –3, 比较不方便. 有时候, 也许想远程直接生成并检查一下服务器的ThreadDump, 这个怎么办呢? 幸好我们有以下代码可以做到:
util.threaddump.ThreadDumpBuilder.java
package util.threaddump;
import java.util.Map;
/**
* 使用 Java 远程代码生成 ThreadDump. 适用于 JDK 1.5+.
* 参考: {@link Thread#getStackTrace()}
* {@link Throwable#getStackTrace()}
* @see StackTraceElement
* @author beansoft@126.com
* 转载请注明出处: beansoft.blogjava.net
*/
public class ThreadDumpBuilder {
/**
* 生成并返回 Thread Dump.
* 转载请注明出处: beansoft.blogjava.net
* @return
*/
public String build() {
StringBuilder output = new StringBuilder(1000);
for (Map.Entry stackTrace : Thread.getAllStackTraces().entrySet()) {
appendThreadStackTrace(output, (Thread) stackTrace.getKey(),
(StackTraceElement[]) stackTrace.getValue());
}
return output.toString();
}/**
* 处理并输出堆栈信息.
* @param output
* 输出内容
* @param thread
* 线程
* @param stack
* 线程堆栈
*/
private void appendThreadStackTrace(StringBuilder output, Thread thread,
StackTraceElement[] stack) {
// 忽略当前线程的堆栈信息
if (thread.equals(Thread.currentThread())) {
return;
}output.append(thread).append("\n");
for (StackTraceElement element : stack) {
output.append("\t").append(element).append("\n");
}
}}
然后在一个JSP里或者Servlet中任意调用即可:
<%=new ThreadDumpBuilder().build() %>
我用的 Oracle JRocket ReamTime 的JVM跑的空的Tomcat, 输出内容如下:
Thread[(GC Main Thread),5,system] Thread[Main Thread,5,main] java.net.PlainSocketImpl.socketAccept(Native Method) java.net.PlainSocketImpl.accept(PlainSocketImpl.java:384) java.net.ServerSocket.implAccept(ServerSocket.java:453) java.net.ServerSocket.accept(ServerSocket.java:421) org.apache.catalina.core.StandardServer.await(StandardServer.java:389) org.apache.catalina.startup.Catalina.await(Catalina.java:630) org.apache.catalina.startup.Catalina.start(Catalina.java:590) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:597) org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288) org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413) Thread[TP-Processor1,5,main] java.lang.Object.wait(Native Method) java.lang.Object.wait(Object.java:485) org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:658) java.lang.Thread.run(Thread.java:619) Thread[TP-Processor3,5,main] java.lang.Object.wait(Native Method) java.lang.Object.wait(Object.java:485) org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:658) java.lang.Thread.run(Thread.java:619) Thread[(VM Periodic Task),10,system] Thread[ContainerBackgroundProcessor[StandardEngine[Catalina]],5,main] java.lang.Thread.sleep(Native Method) org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1579) java.lang.Thread.run(Thread.java:619) Thread[Finalizer,8,system] java.lang.Thread.run(Thread.java:619) Thread[TP-Processor2,5,main] java.lang.Object.wait(Native Method) java.lang.Object.wait(Object.java:485) org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:658) java.lang.Thread.run(Thread.java:619) Thread[Reference Handler,10,system] java.lang.ref.Reference.waitForActivatedQueue(Native Method) java.lang.ref.Reference.access$100(Reference.java:11) java.lang.ref.Reference$ReferenceHandler.run(Reference.java:79) Thread[(Code Generation Thread 1),5,system] Thread[TP-Processor4,5,main] java.net.PlainSocketImpl.socketAccept(Native Method) java.net.PlainSocketImpl.accept(PlainSocketImpl.java:384) java.net.ServerSocket.implAccept(ServerSocket.java:453) java.net.ServerSocket.accept(ServerSocket.java:421) org.apache.jk.common.ChannelSocket.accept(ChannelSocket.java:306) org.apache.jk.common.ChannelSocket.acceptConnections(ChannelSocket.java:660) org.apache.jk.common.ChannelSocket$SocketAcceptor.runIt(ChannelSocket.java:870) org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:686) java.lang.Thread.run(Thread.java:619) Thread[http-8080-Acceptor-0,5,main] java.net.PlainSocketImpl.socketAccept(Native Method) java.net.PlainSocketImpl.accept(PlainSocketImpl.java:384) java.net.ServerSocket.implAccept(ServerSocket.java:453) java.net.ServerSocket.accept(ServerSocket.java:421) org.apache.tomcat.util.net.DefaultServerSocketFactory.acceptSocket(DefaultServerSocketFactory.java:61) org.apache.tomcat.util.net.JIoEndpoint$Acceptor.run(JIoEndpoint.java:310) java.lang.Thread.run(Thread.java:619) Thread[(Signal Handler),5,system] Thread[(Sensor Event Thread),5,system] Thread[TP-Monitor,5,main] java.lang.Object.wait(Native Method) org.apache.tomcat.util.threads.ThreadPool$MonitorRunnable.run(ThreadPool.java:561) java.lang.Thread.run(Thread.java:619) Thread[(Attach Listener),5,system] Thread[(Code Optimization Thread 1),5,system]
对比用 Ctrl + Break 做出的GC, 显然因为有安全性的限制, 输出的日志信息比上面的方式详细的多, 因此这仍然是推荐做法:
===== FULL THREAD DUMP ===============
Sun Aug 16 15:37:48 2009
BEA JRockit(R) R27.6.3-40_o-112056-1.6.0_11-20090318-2104-windows-ia32
"Main Thread" id=1 idx=0x4 tid=1760 prio=5 alive, in native
at java/net/PlainSocketImpl.socketAccept(Ljava/net/SocketImpl;)V(Native Method)
at java/net/PlainSocketImpl.accept(PlainSocketImpl.java:384)
^-- Holding lock: java/net/SocksSocketImpl@0x017CA398[biased lock]
at java/net/ServerSocket.implAccept(ServerSocket.java:453)
at java/net/ServerSocket.accept(ServerSocket.java:421)
at org/apache/catalina/core/StandardServer.await(StandardServer.java:389)
at org/apache/catalina/startup/Catalina.await(Catalina.java:630)
at org/apache/catalina/startup/Catalina.start(Catalina.java:590)
at jrockit/vm/RNI.c2java(IIIII)V(Native Method)
at jrockit/vm/Reflect.invokeMethod(Ljava/lang/Object;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;(Native
Method)
at sun/reflect/NativeMethodAccessorImpl.invoke0(Ljava/lang/reflect/Method;Ljava/lang/Object;[Ljava/lang/Object;)Ljav
a/lang/Object;(Native Method)
at sun/reflect/NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun/reflect/DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java/lang/reflect/Method.invoke(Method.java:597)
at org/apache/catalina/startup/Bootstrap.start(Bootstrap.java:288)
at org/apache/catalina/startup/Bootstrap.main(Bootstrap.java:413)
at jrockit/vm/RNI.c2java(IIIII)V(Native Method)
-- end of trace
"(Signal Handler)" id=2 idx=0x8 tid=1368 prio=5 alive, in native, daemon
"(GC Main Thread)" id=3 idx=0xc tid=1912 prio=5 alive, in native, native_waiting, daemon
"(GC Worker Thread 1)" id=? idx=0x10 tid=2760 prio=5 alive, in native, daemon
"(GC Worker Thread 2)" id=? idx=0x14 tid=1432 prio=5 alive, in native, daemon
"(Code Generation Thread 1)" id=4 idx=0x18 tid=2104 prio=5 alive, in native, native_waiting, daemon
"(Code Optimization Thread 1)" id=5 idx=0x1c tid=1136 prio=5 alive, in native, native_waiting, daemon
"(VM Periodic Task)" id=6 idx=0x20 tid=2184 prio=10 alive, in native, daemon
"(Attach Listener)" id=7 idx=0x24 tid=2464 prio=5 alive, in native, daemon
"Finalizer" id=8 idx=0x28 tid=2668 prio=8 alive, in native, native_waiting, daemon
at jrockit/memory/Finalizer.waitForFinalizees([Ljava/lang/Object;)I(Native Method)
at jrockit/memory/Finalizer.access$500(Finalizer.java:12)
at jrockit/memory/Finalizer$4.run(Finalizer.java:159)
at java/lang/Thread.run(Thread.java:619)
at jrockit/vm/RNI.c2java(IIIII)V(Native Method)
-- end of trace
"Reference Handler" id=9 idx=0x2c tid=772 prio=10 alive, in native, native_waiting, daemon
at java/lang/ref/Reference.waitForActivatedQueue()Ljava/lang/ref/Reference;(Native Method)
at java/lang/ref/Reference.access$100(Reference.java:11)
at java/lang/ref/Reference$ReferenceHandler.run(Reference.java:79)
at jrockit/vm/RNI.c2java(IIIII)V(Native Method)
-- end of trace
"(Sensor Event Thread)" id=10 idx=0x30 tid=280 prio=5 alive, in native, daemon
"ContainerBackgroundProcessor[StandardEngine[Catalina]]" id=12 idx=0x34 tid=3616 prio=5 alive, in native, sleeping, nati
ve_waiting, daemon
at java/lang/Thread.sleep(J)V(Native Method)
at org/apache/catalina/core/ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1579)
at java/lang/Thread.run(Thread.java:619)
at jrockit/vm/RNI.c2java(IIIII)V(Native Method)
-- end of trace
"http-8080-Acceptor-0" id=13 idx=0x38 tid=2780 prio=5 alive, in native, daemon
at java/net/PlainSocketImpl.socketAccept(Ljava/net/SocketImpl;)V(Native Method)
at java/net/PlainSocketImpl.accept(PlainSocketImpl.java:384)
^-- Holding lock: java/net/SocksSocketImpl@0x031F98D0[biased lock]
at java/net/ServerSocket.implAccept(ServerSocket.java:453)
at java/net/ServerSocket.accept(ServerSocket.java:421)
at org/apache/tomcat/util/net/DefaultServerSocketFactory.acceptSocket(DefaultServerSocketFactory.java:61)
at org/apache/tomcat/util/net/JIoEndpoint$Acceptor.run(JIoEndpoint.java:310)
at java/lang/Thread.run(Thread.java:619)
at jrockit/vm/RNI.c2java(IIIII)V(Native Method)
-- end of trace
"TP-Processor1" id=14 idx=0x3c tid=3184 prio=5 alive, in native, waiting, daemon
-- Waiting for notification on: org/apache/tomcat/util/threads/ThreadPool$ControlRunnable@0x0179EB28[fat lock]
at jrockit/vm/Threads.waitForNotifySignal(JLjava/lang/Object;)Z(Native Method)
at java/lang/Object.wait(J)V(Native Method)
at java/lang/Object.wait(Object.java:485)
at org/apache/tomcat/util/threads/ThreadPool$ControlRunnable.run(ThreadPool.java:658)
^-- Lock released while waiting: org/apache/tomcat/util/threads/ThreadPool$ControlRunnable@0x0179EB28[fat lock]
at java/lang/Thread.run(Thread.java:619)
at jrockit/vm/RNI.c2java(IIIII)V(Native Method)
-- end of trace
"TP-Processor2" id=15 idx=0x40 tid=2336 prio=5 alive, in native, waiting, daemon
-- Waiting for notification on: org/apache/tomcat/util/threads/ThreadPool$ControlRunnable@0x0179EF40[fat lock]
at jrockit/vm/Threads.waitForNotifySignal(JLjava/lang/Object;)Z(Native Method)
at java/lang/Object.wait(J)V(Native Method)
at java/lang/Object.wait(Object.java:485)
at org/apache/tomcat/util/threads/ThreadPool$ControlRunnable.run(ThreadPool.java:658)
^-- Lock released while waiting: org/apache/tomcat/util/threads/ThreadPool$ControlRunnable@0x0179EF40[fat lock]
at java/lang/Thread.run(Thread.java:619)
at jrockit/vm/RNI.c2java(IIIII)V(Native Method)
-- end of trace
"TP-Processor3" id=16 idx=0x44 tid=2644 prio=5 alive, in native, waiting, daemon
-- Waiting for notification on: org/apache/tomcat/util/threads/ThreadPool$ControlRunnable@0x0179F400[fat lock]
at jrockit/vm/Threads.waitForNotifySignal(JLjava/lang/Object;)Z(Native Method)
at java/lang/Object.wait(J)V(Native Method)
at java/lang/Object.wait(Object.java:485)
at org/apache/tomcat/util/threads/ThreadPool$ControlRunnable.run(ThreadPool.java:658)
^-- Lock released while waiting: org/apache/tomcat/util/threads/ThreadPool$ControlRunnable@0x0179F400[fat lock]
at java/lang/Thread.run(Thread.java:619)
at jrockit/vm/RNI.c2java(IIIII)V(Native Method)
-- end of trace
"TP-Processor4" id=17 idx=0x48 tid=1384 prio=5 alive, in native, daemon
at java/net/PlainSocketImpl.socketAccept(Ljava/net/SocketImpl;)V(Native Method)
at java/net/PlainSocketImpl.accept(PlainSocketImpl.java:384)
^-- Holding lock: java/net/SocksSocketImpl@0x0176E128[biased lock]
at java/net/ServerSocket.implAccept(ServerSocket.java:453)
at java/net/ServerSocket.accept(ServerSocket.java:421)
at org/apache/jk/common/ChannelSocket.accept(ChannelSocket.java:306)
at org/apache/jk/common/ChannelSocket.acceptConnections(ChannelSocket.java:660)
at org/apache/jk/common/ChannelSocket$SocketAcceptor.runIt(ChannelSocket.java:870)
at org/apache/tomcat/util/threads/ThreadPool$ControlRunnable.run(ThreadPool.java:686)
at java/lang/Thread.run(Thread.java:619)
at jrockit/vm/RNI.c2java(IIIII)V(Native Method)
-- end of trace
"TP-Monitor" id=18 idx=0x4c tid=2788 prio=5 alive, in native, waiting, daemon
-- Waiting for notification on: org/apache/tomcat/util/threads/ThreadPool$MonitorRunnable@0x0179FBB0[fat lock]
at jrockit/vm/Threads.waitForNotifySignal(JLjava/lang/Object;)Z(Native Method)
at java/lang/Object.wait(J)V(Native Method)
at org/apache/tomcat/util/threads/ThreadPool$MonitorRunnable.run(ThreadPool.java:561)
^-- Lock released while waiting: org/apache/tomcat/util/threads/ThreadPool$MonitorRunnable@0x0179FBB0[fat lock]
at java/lang/Thread.run(Thread.java:619)
at jrockit/vm/RNI.c2java(IIIII)V(Native Method)
-- end of trace
"http-8080-1" id=20 idx=0x50 tid=2192 prio=5 alive, in native, waiting, daemon
-- Waiting for notification on: org/apache/tomcat/util/net/JIoEndpoint$Worker@0x016649A8[fat lock]
at jrockit/vm/Threads.waitForNotifySignal(JLjava/lang/Object;)Z(Native Method)
at java/lang/Object.wait(J)V(Native Method)
at java/lang/Object.wait(Object.java:485)
at org/apache/tomcat/util/net/JIoEndpoint$Worker.await(JIoEndpoint.java:416)
^-- Lock released while waiting: org/apache/tomcat/util/net/JIoEndpoint$Worker@0x016649A8[fat lock]
at org/apache/tomcat/util/net/JIoEndpoint$Worker.run(JIoEndpoint.java:442)
at java/lang/Thread.run(Thread.java:619)
at jrockit/vm/RNI.c2java(IIIII)V(Native Method)
-- end of trace
===== END OF THREAD DUMP ===============
参考资料:
1. Atlassian Confluence 3.0 管理控制台
2. JDK的DEMO
jdk1.5.0\demo\management\FullThreadDump
相关推荐
不同的Java虚拟机(JVM)有不同的方式来生成Thread Dump: - **Sun JVM**: - 在Solaris OS中,可以通过按下`<ctrl>-'\'' (Control-Backslash) 或者使用 `kill -QUIT <pid>` 命令来生成。 - 在HP-UX/UNIX/Linux中,...
而`heapdump`文件则是JVM在运行过程中,通过Java的`jmap`命令或者`VisualVM`等工具手动触发生成的,它记录了JVM堆内存的详细状态,包括对象实例、类加载器、垃圾收集信息等。`ha`(Heap Analysis)工具则用于分析`...
总结来说,IBM Thread and Monitor Dump Analyzer for Java (jca37)是一个强大的故障排查工具,它通过对内存溢出和javacore文件的深入分析,帮助开发者定位和修复Java应用中的性能问题。通过熟练使用这款工具,我们...
1. **生成heap dump**:在JVM启动时添加`-XX:+HeapDumpOnOutOfMemoryError`参数,或者通过JMX、JConsole等方式手动触发dump生成。 2. **下载并安装分析工具**:如VisualVM或MAT,确保其版本与JVM兼容。 3. **加载...
`deapdump`(也称为`thread dump`或`heap dump`)是另一种重要的诊断工具,它提供了更深入的内存分析。当WebSphere遇到问题时,可以通过触发deapdump获取当前JVM的线程详细信息以及堆内存快照。堆内存快照可以揭示...
1. **获取javacore日志**:可以通过WebSphere管理控制台,或者在命令行中使用`jstack`命令(如果是Linux/Unix环境,需要root权限)来触发生成javacore日志。 2. **打开Thread工具**:IBM提供了多种工具来解析java...
1. **获取线程Dump**:使用`jstack`命令或者在JVM参数中设置`-XX:+HeapDumpOnOutOfMemoryError`来触发Dump生成。 2. **解压`TDA`**:将`tda-bin-2.2.zip`解压到本地,确保目录结构完整。 3. **启动`TDA`**:运行...
本文将深入探讨Java线程Dump的概念、生成方式以及如何通过分析线程Dump来诊断和解决性能瓶颈。 **第1章 JAVA线程DUMP** 1.1 什么是JAVA线程DUMP Java线程Dump,也称为线程快照,是JVM在特定时刻捕获的所有活动...
- **发送特定信号**:在某些情况下,可以通过向运行中的Java应用程序发送特定信号来触发Javacore文件的生成。例如,在Linux系统上,可以使用`kill -3 <pid>`命令(其中`<pid>`为Java进程的ID),这将生成一个Java...
1. **获取javacore**:可以通过JVM命令行参数或操作系统的信号来触发生成,也可以通过IBM Java的`jconsole`或`jvisualvm`等工具手动获取。 2. **解析javacore**:IBM提供了专门的工具,如`IBM Heap Analyzer`,它...
本文将详细介绍多种Java调试工具及其使用方法,并通过实例演示如何利用这些工具来定位并解决常见的Java应用问题。 #### 一、诊断工具概述 在深入探讨具体的调试工具之前,我们首先简要介绍Java平台提供的诊断工具。...
或者,我们也可以通过JVisualVM或jmap工具手动触发dump文件的生成。 一旦有了dump文件,接下来就是导入到MAT。启动MAT,点击“Open Heap Dump”按钮,选择相应的dump文件。MAT将读取文件并对其进行解析,这个过程...
“threaddump”和“heapdump”都是jca和ha工具的主要应用场景。 在实际使用中,开发者可以先通过jca获取线程堆栈信息,找出可能的线程问题,如死锁、过度的线程创建等。然后,如果发现内存使用异常,如频繁的Full ...
JVM的线程Dump,即Threaddump,是另一种诊断工具,它提供了每个线程的当前状态,包括栈跟踪。线程Dump在分析死锁、阻塞等问题时非常有用。通过分析线程的调用栈,我们可以看到每个线程正在执行哪些方法,从而发现...
生成JavaCore和HeapDump文件可以通过发送特定信号(通常是`kill -3`)给Java进程来实现。在Unix/Linux系统中,首先使用`ps -ef | grep java`找到Java进程的PID,然后执行`kill -3 PID`命令。这将触发JVM生成JavaCore...
2. **Thread Dump生成**:当一个请求的处理时间超过预设阈值时,监控程序会自动触发Thread Dump。Thread Dump是一个快照,显示了在特定时刻JVM中的所有线程的状态,包括它们当前执行的方法和等待的锁。这可以帮助...