Java Tomcat线程转储

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18573411/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 09:07:17  来源:igfitidea点击:

Tomcat thread dump

javatomcatpermgenthread-dump

提问by Abdullah

Is there away to take a thread dumpfrom Tomcat. I want to monitor the running threads on Tomcat at a certain time.

是否可以从 Tomcat进行线程转储。我想在某个时间监控Tomcat上正在运行的线程。

Note:I was doing that on Web logic but i don't know how it cab be done on Tomcat.

注意:我是在 Web 逻辑上这样做的,但我不知道它是如何在 Tomcat 上完成的。

采纳答案by Julien

If you use Linux, you can send a kill -3 [pid of your tomcat] and it will dump all current threads in the catalina.out.

如果你使用 Linux,你可以发送一个 kill -3 [你的 tomcat 的 pid],它会转储 catalina.out 中的所有当前线程。

回答by Prabhakaran Ramaswamy

Please try netbeans profiler to profile any web applications.

请尝试使用 netbeans 分析器来分析任何 Web 应用程序。

https://profiler.netbeans.org/

https://profiler.netbeans.org/

http://wiki.netbeans.org/FaqProfilerAttachRemoteServer

http://wiki.netbeans.org/FaqProfilerAttachRemoteServer

回答by olexii

add java melody to your server https://code.google.com/p/javamelody/

将 java melody 添加到您的服务器 https://code.google.com/p/javamelody/

it give you a lot of info including threads in runtime

它为您提供了很多信息,包括运行时的线程

回答by Patrik Bego

There is a simple way to monitor tomcat threads and do a dump. Start tomcat with the folowing java options :

有一种简单的方法可以监控 tomcat 线程并进行转储。使用以下 java 选项启动 tomcat:

-Dcom.sun.management.jmxremote.port=<some free port>
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false

After the tomcat is restarted you can simply start jconsole (part of jdk) or visualvm and create a new jmx connection to the port you have chosen above.
In both tools you also have an option to take a dump ;)

重启tomcat后,您可以简单地启动jconsole(jdk的一部分)或visualvm并创建一个新的jmx连接到您在上面选择的端口。
在这两种工具中,您还可以选择进行转储;)

!!!But do that only in closed/secured environment - since there is no authentication set.!!!

!!!但只能在封闭/安全的环境中这样做 - 因为没有设置身份验证。!!!

回答by Guido Medina

The following steps should help you get the current Java threads running and analyze them:

以下步骤应该可以帮助您运行当前的 Java 线程并对其进行分析:

  1. Download IBM JCA which is a nice thread dump analyzer from IBM Thread & Dump Monitor Analyzer
  2. Execute the following to get the Tomcat threads dump: root@localhost:~# sudo -u $TOMCAT_USER $JAVA_HOME/bin/jstack -J-d64 -l $(ps aux | grep '[c]atalina' | awk '{print $2}') > ~/threads.log
  3. Open the threads dump with IBM Thread & Dump Monitor Analyzer
  1. IBM Thread & Dump Monitor Analyzer下载 IBM JCA,这是一个不错的线程转储分析器
  2. 执行以下命令以获取 Tomcat 线程转储: root@localhost:~# sudo -u $TOMCAT_USER $JAVA_HOME/bin/jstack -J-d64 -l $(ps aux | grep '[c]atalina' | awk '{print $2}') > ~/threads.log
  3. 使用IBM Thread & Dump Monitor Analyzer打开线程转储

Note:Replace $JAVA_HOMEwith your path to your current JDK, $TOMCAT_USERwith the user running Tomcat; if you pass the wrong user or even using root you will get an error like this:

注意:替换$JAVA_HOME为您当前 JDK 的路径,$TOMCAT_USER用户运行 Tomcat;如果您传递了错误的用户,甚至使用了 root 用户,您将收到如下错误:

3047: well-known file is not secure