Linux/Unix

1. Find the Java/Tomcat process id.

% ps ax | grep java

You should see output like this

17207 ?        Sl    78:36 /usr/java/default/bin/java -Djava.util.logging.config.file=/usr/tomcat/tomcat6/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xmx1024M -Xms128M -XX:MaxPermSize=256M -Djava.awt.headless=true -Djava.endorsed.dirs=/usr/tomcat/tomcat6/endorsed -classpath :/usr/tomcat/tomcat6/bin/bootstrap.jar -Dcatalina.base=/usr/tomcat/tomcat6 -Dcatalina.home=/usr/tomcat/tomcat6 -Djava.io.tmpdir=/usr/tomcat/tomcat6/temp org.apache.catalina.startup.Bootstrap start

2. Execute the following command to generate a thread dump

 % kill -3 <pid>

Run this command every 5-10 seconds, 5 times.

3.The thread dump is written to the standard output.  It may logged in the console or <tomcat>/logs/stdout or <tomcat>/logs/catalina.out.

4. If you are running JDK 6.0+, you may also use jstack to produce a thread dump.

 % jstack -l <pid> > threaddump.txt
or
% jstack <pid> > threaddump.txt

Windows

Running as a Windows service

1a. If installed using Tomcat installer, click All Programs ->Apache Tomcat 6.0->Monitor Tomcat. An icon should appear in task bar.

1b. If not installed using Tomcat installer, navigate to <tomcat>/bin, and run the following command

 % tomcat7.exe //MS//Tomcat7

The Tomcat monitor icon should appear in the system tray.;

2. Right click the the icon and select Thread Dump.

Run this command every 5-10 seconds, 5 times

3. Look for the thread dump in  <tomcat>/logs/stdout or <tomcat>/logs/catalina.out.

Running from startup.bat

1. Open "Windows Task Manager",

2. Find the process ID of the java process

3. Make sure <JDK>/bin is in your command path. Otherwise, navigate to <JDK>/bin

4. Execute the following command to generate a thread dump

 % jstack -l <pid> >  threaddump.txt

Run this command every 5-10 seconds, 5 times

If you receive an error running jstack such as the below, then you may need to use psexec:

7988: Insufficient memory or insufficient privileges to attach
The -F option can be used when the target process is not responding
 
1. Download psexec from this website.
2. Unzip the 'PSTools' directory to a suitable place on your server.
3. Open a command prompt as Administrator and navigate to the location of the PSTools folder using the command prompt.
 
 
4. Open Task Manager > Services and find your Java (Tomcat) service and note down the PID number.
 

 5. At the command prompt type 'psexec -s [jdk path]\jstack.exe XXXX >> thread_dump_ddmmyy.log' (where XXXX is your PID and ddmmyy is the current date to append to the name of the log file) then hit enter. 
 
 

Run this command every 5-10 seconds, 5 times

You can also add the full path of your Java 'bin' directory to the server's system path variable. The Java 'bin' directory is usually in 'Program Files\Java\bin\jdk<version>\bin'.  If you add this path to the system variable then you will need to restart the command prompt again for the change to be picked up and the 'jstack' command to work.

reference from:
http://support.jamasoftware.com/entries/20535318-Performing-a-thread-dump-in-Linux-or-Windows

Performing a thread dump in Linux or Windows--reference的更多相关文章

  1. 013-程序性能分析之thread dump和heap dump

    一.dump基本概念 主要用于故障定位(尤其是out of memory)和性能分析.主要记录了JVM运行期间的内存占用.线程执行等情况,这就是常说的dump文件.常用的有heap dump和thre ...

  2. 性能分析之-- JAVA Thread Dump 分析综述

    性能分析之-- JAVA Thread Dump 分析综述       一.Thread Dump介绍 1.1什么是Thread Dump? Thread Dump是非常有用的诊断Java应用问题的工 ...

  3. [转]Java Thread Dump 性能分析

    Java and Thread 一个 web 服务器使用几十到几百个线程来处理大量并发用户,如果一个或多个线程使用相同的资源,线程之间的竞争就不可避免了,并且有时候可能会发生死锁. Thread co ...

  4. thread dump

    最近在做性能测试,需要对线程堆栈进行分析,在网上收集了一些资料,学习完后,将相关知识整理在一起,输出文章如下. 一.Thread Dump介绍 1.1什么是Thread Dump? Thread Du ...

  5. 如何抓取Thread Dump小结(转)

    当系统性能出现问题时,需要从各个方面来查看网络环境.主机资源.查看最经变更的代码等.如果是想从代码层面解决问题,那么最有效的方法就是查看相关dump文件.如果是使用IBM JDK(我默认你是在aix环 ...

  6. Thread Dump 和Java应用诊断(转)

    Thread Dump 和Java应用诊断 Thread Dump是非常有用的诊断Java应用问题的工具,每一个Java虚拟机都有及时生成显示所有线程在某一点状态的thread-dump的能力.虽然各 ...

  7. java程序性能分析之thread dump和heap dump

    一.dump基本概念 在故障定位(尤其是out of memory)和性能分析的时候,经常会用到一些文件来帮助我们排除代码问题.这些文件记录了JVM运行期间的内存占用.线程执行等情况,这就是我们常说的 ...

  8. java jvm heap dump及 thread dump分析

    一.概念: 在进行java应用故障分析时,经常需要分析内存和cpu信息,也就说所谓的heap dump 和 thread dump heap dump: heap dump文件是一个二进制文件,需要工 ...

  9. [JAVA]JAVA章4 Thread Dump如何分析

    一.Thread Dump介绍 1.1什么是Thread Dump? Thread Dump是非常有用的诊断Java应用问题的工具.每一个Java虚拟机都有及时生成所有线程在某一点状态的thread- ...

随机推荐

  1. BZOJ 1717: [Usaco2006 Dec]Milk Patterns 产奶的模式

    Description 农夫John发现他的奶牛产奶的质量一直在变动.经过细致的调查,他发现:虽然他不能预见明天产奶的质量,但连续的若干天的质量有很多重叠.我们称之为一个"模式". ...

  2. ReactEurope Conf 参会感想

    React 带来的革命性创新是前端世界过去几年最激动人心的变化.自从接触 React 以来,我深信 React 会改变客户端开发者(包括前端.iOS 和 Android)的开发体验.这次在巴黎举办的  ...

  3. Android应用架构

    Android开发生态圈的节奏非常之快.每周都会有新的工具诞生,类库的更新,博客的发表以及技术探讨.如果你外出度假一个月,当你回来的时候可能已经发布了新版本的Support Library或者Play ...

  4. Android Training精要(六)如何防止Bitmap对象出现OOM

    1.使用AsyncTask異步加載bitmap圖片避免OOM: class BitmapWorkerTask extends AsyncTask<Integer, Void, Bitmap> ...

  5. 最全的JAVA源码整合下载

    http://www.360doc.com/content/14/0602/00/11407612_382890953.shtml http://www.360doc.com/content/14/0 ...

  6. WebService开发应用

    WebService是运行于服务端(一般放在信息服务器上的)让客户端来调用的. 以下开发两个简单的实例 1.自己开发服务端自己调用(vs2010) 1).菜单:“新建-项目”,在打开的窗体中选择,如下 ...

  7. VS代码文件中添加协议格式

    //数据帧格式如下 //+-------+-------+-------+-------+---------+------+-------+ //|包头(2)|地址(1)|功能(1)|长度(1)|数据 ...

  8. android 获取设备唯一标识完美解决方案

    /** * deviceID的组成为:渠道标志+识别符来源标志+hash后的终端识别符 * * 渠道标志为: * 1,andriod(a) * * 识别符来源标志: * 1, wifi mac地址(w ...

  9. BASH小脚本

    1.查找当前目录中所有大于500M的文件,把这些文件名写到一个文本文件中,并统计其个数. find ./ -size +500M -type f | tee file_list | wc -l 2.在 ...

  10. iPhone/Mac Objective-C内存管理教程和原理剖析

    http://www.cocoachina.com/bbs/read.php?tid-15963.html 版权声明 此文版权归作者Vince Yuan (vince.yuan#gmail.com)所 ...