螺纹转储分析工具/方法 [英] Thread Dump Analysis Tool / Method

查看:183
本文介绍了螺纹转储分析工具/方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当Java应用程序挂起时,您甚至不知道导致此问题的用例,并希望进行调查,我了解线程转储可以是有用的。



但是,如何轻松地从线程转储中导出有用的数据来查找问题的位置?我一直在使用的服务器应用程序产生了很长的线程转储,因为它是一个EJB架构,线程转储包含许多容器线程,我不知道我应该查看(即,没有运行我的应用程序代码的线程,但JBoss的代码)。



昨天我尝试了(我没有使用TDA自己),它将突出显示这些红色,所以你可以快速点击它,并找到显示问题的线。



查看这里这里。看看那个链接中的武士输出图像。绿色细胞很好。红色和灰色单元格需要查看。



以下我自己的Web应用程序中的一个武士示例显示了Thread'19'跨越5 - 10秒的卡纸顺序

 >线程转储2/3[ACTIVE] ExecuteThread:队列的'19':
>'weblogic.kernel.Default
>(自调整)'daemon prio = 7
> tid = 07b06000 nid = 108 lwp_id = 222813
>等待监视器条目
> [2aa40000..2aa40b30]
> java.lang.Thread.State:
>上的BLOCKED(在
>对象监视器上) com.bea.p13n.util.lease.JDBCLeaseManager.renewLease(JDBCLeaseManager.java:393)
> - 等待锁定< 735e9f88> (com.bea.p13n.util.lease.JDBCLeaseManager)
>在
> com.bea.p13n.util.lease.Lease $ LeaseTimer.timerExpired(Lease.java:229)

...

 >线程转储3/3[ACTIVE] 
> ExecuteThread:'19'作为队列:
>'weblogic.kernel.Default
>(自调整)'守护进程= 7
> tid = 07b06000 nid = 108 lwp_id = 222813
>等待监视器条目
> [2aa40000..2aa40b30]
> java.lang.Thread.State:
>上的BLOCKED(在
>对象监视器上) com.bea.p13n.util.lease.JDBCLeaseManager.renewLease(JDBCLeaseManager.java:393)
> - 等待锁定< 735e9f88> (com.bea.p13n.util.lease.JDBCLeaseManager)
>在
> com.bea.p13n.util.lease.Lease $ LeaseTimer.timerExpired(Lease.java:229)

更新



我最近使用了在这个答案中提到了 ,对于Tomcat而言,这是非常有用的,而不是武士


When the Java application is hanging, you don't even know the use case that is leading to this and want to investigate, I understand that thread dumps can be useful.

But how can we easily derive useful data from the thread dumps to find where the problem is? The server application that I've been working with produces very long thread dumps, because it is an EJB architecture and thread dumps contains many container threads that I'm not sure I should be looking at (i.e. threads that are not running my application code, but JBoss's code).

Yesterday I tried the Thread Dump Analyzer tool. The tool is definitely better than looking at the raw thread dumps in a text editor, because you can filter out threads that you're not interested in, see the thread list, click on a thread to see its details, compare thread dumps to find long running threads, etc. See screenshot below:

But there's still too much data to analyse - almost 300 threads. I don't know of any criteria that I could use to filter out all the JBoss threads, in which I'm not interested. I'm not sure if I should be looking at threads that are currently in "runnable" state only or if "waiting on condition" and "in Object.wait" are also important.

What's the approach that you would normally follow and tools that you would in general use?

解决方案

One set of thread dumps alone will not be too helpful to get to the root cause.

The trick is to take 4 or 5 sets of thread dumps at an interval of 5 seconds between each. so at the end you will have a single log file which has around 20 - 25 seconds worth of action on the app server.

What you want to check is when a stuck thread or long running transaction happens, all the thread dumps will show a certain thread id is at the same line in your java stack trace. In simpler terms, the transaction (say in an EJB or database) is spanning across multiple thread dumps and hence needs more investigation.

Now when you run these through Samurai (I havent used TDA myself), it will highlight these in Red colour so you can quickly click on it and get to the lines showing issues.

See an example of this here. Look at the Samurai output image in that link. The Green cells are fine. Red and Grey cells need looking at.

A Samurai example from my own web app below shows a stuck sequence for Thread'19' across a span of 5 - 10 seconds

>     Thread dump 2/3 "[ACTIVE] ExecuteThread: '19' for queue:
> 'weblogic.kernel.Default
> (self-tuning)'" daemon prio=7
> tid=07b06000 nid=108 lwp_id=222813
> waiting for monitor entry
> [2aa40000..2aa40b30]     
> java.lang.Thread.State: BLOCKED (on
> object monitor)      at
> com.bea.p13n.util.lease.JDBCLeaseManager.renewLease(JDBCLeaseManager.java:393)
> - waiting to lock <735e9f88> (a com.bea.p13n.util.lease.JDBCLeaseManager)
> at
> com.bea.p13n.util.lease.Lease$LeaseTimer.timerExpired(Lease.java:229)

...

> Thread dump 3/3 "[ACTIVE]
> ExecuteThread: '19' for queue:
> 'weblogic.kernel.Default
> (self-tuning)'"   daemon prio=7
> tid=07b06000 nid=108 lwp_id=222813
> waiting for monitor entry
> [2aa40000..2aa40b30]     
> java.lang.Thread.State: BLOCKED (on
> object monitor)      at
> com.bea.p13n.util.lease.JDBCLeaseManager.renewLease(JDBCLeaseManager.java:393)
> - waiting to lock <735e9f88> (a com.bea.p13n.util.lease.JDBCLeaseManager)
> at
> com.bea.p13n.util.lease.Lease$LeaseTimer.timerExpired(Lease.java:229)

update

I recently used the Java Thread Dump Analyzer mentioned in this answer and it's been very useful for Tomcat as opposed to Samurai

这篇关于螺纹转储分析工具/方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆