Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to grab and analyze Thread Dump

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

I. grasping

1. Ps-ef | grep java

2. Jstack-l > 111.txt

2. Analysis

Thread status in jstack Dump log files

In the dump file, the thread states that are worth watching are:

Deadlock, Deadlock (focus)

In progress, Runnable

Wait for resources, Waiting on condition (focus)

Waiting to get the monitor, Waiting on monitor entry (focus)

Pause, Suspended

Object waiting, Object.wait () or TIMED_WAITING

Blocking, Blocked (focus)

Stop, Parked

Let's start with the first example, then list the meaning and considerations of different thread states, and finally add two examples.

Comprehensive demonstration 1: Waiting to lock and Blocked

Examples are as follows:

"RMI TCP Connection (267865)-172.16.5.25" daemon prio=10 tid=0x00007fd508371000 nid=0x55ae waiting for monitor entry [0x00007fd4f8684000]

Java.lang.Thread.State: BLOCKED (on object monitor)

At org.apache.log4j.Category.callAppenders (Category.java:201)

-waiting to lock (an org.apache.log4j.Logger)

At org.apache.log4j.Category.forcedLog (Category.java:388)

At org.apache.log4j.Category.log (Category.java:853)

At org.apache.commons.logging.impl.Log4JLogger.warn (Log4JLogger.java:234)

At com.tuan.core.common.lang.cache.remote.SpyMemcachedClient.get (SpyMemcachedClient.java:110)

……

1) Thread state is Blocked, blocking state. Indicates that the thread timed out waiting for resources!

2) "waiting to lock" means that a thread is waiting to lock this 0x00000000acf4d0c0 address (English description: trying to obtain 0x00000000acf4d0c0 lock).

3) look up the string 0x00000000acf4d0c0 in the dump log and find that there are a large number of threads waiting to lock this address. If you can find out in the log who acquired the lock (such as locked

< 0x00000000acf4d0c0 >

), and you can follow the trail.

4) "waiting for monitor entry" indicates that this thread passes synchronized (obj) {. } the application enters the critical section, thus entering the "Entry Set" queue in figure 1 below, but the monitor corresponding to the obj is owned by another thread, so this thread waits in the Entry Set queue.

5) in the first line, "RMI TCP Connection (267865)-172.16.5.25" is Thread Name. Tid means Java Thread id. Nid refers to the id of the native thread. Prio is the thread priority. [0x00007fd4f8684000] is the starting address of the thread stack.

The meaning of thread state in Dump file and matters needing attention

The meaning is as follows:

Deadlock: deadlock thread, which generally refers to the situation in which multiple thread calls occupy each other's resources, resulting in a situation that cannot be released.

Runnable: generally speaking, the thread is in a state of execution, takes up resources, is processing a request, may be passing SQL to the database for execution, may be operating on a file, and may perform data type conversion.

Waiting on condition: wait for a resource, or wait for a condition to occur. The specific reasons need to be analyzed in combination with stacktrace.

One situation is that the network is so busy that it consumes almost all the bandwidth, and there is still a lot of data waiting for the network to read and write.

Another situation may be that the network is idle, but due to routing and other problems, the packet can not arrive normally.

If the stack information is clearly application code, it proves that the thread is waiting for the resource. Generally, when a large number of resources are read, and the resource is locked, the thread enters the waiting state and waits for the resource to be read.

Or, waiting for the execution of other threads, etc.

If you find that there are a large number of threads in the Wait on condition, from the thread stack, waiting for the network to read and write, this may be a sign of a network bottleneck. The thread cannot execute because of network congestion.

Another common occurrence of Wait on condition is that the thread is in sleep, and when the time for waiting for sleep is up, it will be woken up.

Blocked: thread blocking means that during the current thread execution, the required resources have been waiting for a long time but have not been obtained. It is identified as a blocking state by the thread manager of the container, which can be understood as a thread waiting for the resource timeout.

Waiting for monitor entry and in Object.wait (): Monitor is the main means to implement mutual exclusion and cooperation between threads in Java. It can be regarded as an object or a lock of Class. Each object has, and only one monitor. As you can see from figure 1 below, each Monitor can only be owned by one thread at some point, that thread is "Active Thread", while the other threads are "Waiting Thread", waiting in two queues "Entry Set" and "Wait Set" respectively. The state of the thread waiting in "Entry Set" is "Waiting for monitor entry", while the state of the thread waiting in "Wait Set" is "in Object.wait ()".

Figure 1 A Java Monitor

Comprehensive demonstration 2: Waiting on condition and TIMED_WAITING

Examples are as follows:

"RMI TCP Connection (idle)" daemon prio=10 tid=0x00007fd50834e800 nid=0x56b2 waiting on condition [0x00007fd4f1a59000]

Java.lang.Thread.State: TIMED_WAITING (parking)

At sun.misc.Unsafe.park (Native Method)

-parking to wait for (a java.util.concurrent.SynchronousQueue$TransferStack)

At java.util.concurrent.locks.LockSupport.parkNanos (LockSupport.java:198)

At java.util.concurrent.SynchronousQueue$TransferStack.awaitFulfill (SynchronousQueue.java:424)

At java.util.concurrent.SynchronousQueue$TransferStack.transfer (SynchronousQueue.java:323)

At java.util.concurrent.SynchronousQueue.poll (SynchronousQueue.java:874)

At java.util.concurrent.ThreadPoolExecutor.getTask (ThreadPoolExecutor.java:945)

At java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:907)

At java.lang.Thread.run (Thread.java:662)

1) the timed_waiting in "TIMED_WAITING (parking)" refers to the waiting state, but the time is specified here, and the waiting state is automatically exited when the specified time is reached; parking means that the thread is suspended.

2) "waiting on condition" needs to be combined with "parking to wait for (a java.util.concurrent.SynchronousQueue$TransferStack)" in the stack. First of all, this thread must be waiting for a condition to happen to wake itself up. Second, SynchronousQueue is not a queue, but a mechanism for transferring information between threads. When we put an element into the SynchronousQueue, another thread must be waiting for the task to be handed over, so this is the condition that the thread is waiting for.

3) nothing else can be seen.

Comprehensive demonstration 3: in Obejct.wait () and TIMED_WAITING

Examples are as follows:

"RMI RenewClean- [172.16.5.19 0x00007f34f4bd0000 28475]" daemon prio=10 tid=0x0000000041428800 nid=0xb09 in Object.wait () [0x00007f34f4bd0000]

Java.lang.Thread.State: TIMED_WAITING (on object monitor)

At java.lang.Object.wait (Native Method)

-waiting on (a java.lang.ref.ReferenceQueue$Lock)

At java.lang.ref.ReferenceQueue.remove (ReferenceQueue.java:118)

-locked (a java.lang.ref.ReferenceQueue$Lock)

At sun.rmi.transport.DGCClient$EndpointEntry$RenewCleanThread.run (DGCClient.java:516)

At java.lang.Thread.run (Thread.java:662)

1) "TIMED_WAITING (on object monitor)", for this example, is because the thread calls java.lang.Object.wait (long timeout) and enters the waiting state.

2) the state of the waiting thread in "Wait Set" is "in Object.wait ()". When the thread gets the Monitor and enters the critical section, if it finds that the conditions for the thread to continue running are not met, it calls the wait () method of the object (usually the object being synchronized), abandons the Monitor and enters the "Wait Set" queue. Only when another thread calls notify () or notifyAll () on the object does the thread in the "Wait Set" queue get a chance to compete, but only one thread gets the object's Monitor and returns to the running state.

3) RMI RenewClean is a part of DGCClient. DGC refers to Distributed GC, that is, distributed garbage collection.

4) Please note that locked is followed by waiting on. The reason why you lock the same object first and then wait for the same object, please see its code implementation below:

Static private class Lock {}

Private Lock lock = new Lock ()

Public Reference

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report