Thread status in the jstack Dump Log FileIn the dump file, the following thread states are worth noting:
- Deadlock,Deadlock (important)
- Running, Runnable
- Waiting for resources,Waiting on condition (important)
- Waiting to get the monitor,Waiting on monitor entry (important)
- Paused, suincluded
- The Object is waiting. The Object. wait () or TIMED_WAITING
- Blocking,Blocked (important)
- Stop, Parked
Next we will first analyze the first example, then list the meanings and precautions of different thread states, and then add two instances.
Comprehensive demonstration 1: Waiting to lock and BlockedExample: "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 <0x00000000acf4d0c0>(A 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) The thread status is
Blocked, Blocking status. This indicates that the thread waits for the resource to time out! 2) "waiting to lock <0x00000000acf4d0c0>" means that the thread is waiting to lock the 0x00000000acf4d0c0 address (trying to obtain 0x00000000acf4d0c0 lock ). 3) Search for the string 0x0000acf4d0c0 in the dump log and find that a large number of threads are waiting to lock the address. If you can find the person in the log who has obtained the lock (such as locked <0x00000000acf4d0c0>), you can easily find it. 4)"
Waiting for monitor entry"Indicates that this thread uses synchronized (obj ){......} The application enters the critical section and enters the "Entry Set" queue in 1. However, the monitor corresponding to this obj is owned by other threads, so this thread waits in the Entry Set queue. 5) In the first line, "rmi tcp Connection (267865)-172.16.5.25" is the Thread Name. Tid indicates the Java Thread id. Nid indicates the id of the native thread. Prio is the thread priority. [0x00007fd4f8684000] is the starting address of the thread stack.
Meaning and precautions of the thread status in the Dump file
The meaning is as follows:
- Deadlock: a Deadlock thread. Generally, it refers to a situation where multiple threads call each other and enter the resource occupation of each other, resulting in waiting for the thread to be released.
- Runnable: indicates that the thread is in the execution status. The thread occupies resources and is processing a request. It may be passing SQL statements to the database for execution, or performing operations on a file, it is possible to convert data types.
- Waiting on condition: Waiting for resources, or Waiting for the occurrence of a condition. The specific cause must be analyzed with stacktrace.
- If the stack information is clearly the application code, it indicates that the thread is waiting for resources. Generally, when a resource is read in large quantities 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.
- If a large number of threads are found to be in the Wait on condition, from the thread stack perspective, they are waiting for network read/write, which may be a network bottleneck. The thread cannot be executed because of network congestion.
- One case is that the network is very busy, consuming almost all the bandwidth, and there is still a large amount of data waiting for network read/write;
- In another case, the network may be idle, but the packets cannot arrive normally due to routing and other problems.
- Another common occurrence of Wait on condition is that the thread is in sleep and will be awakened when the sleep time is reached.
- Blocked: indicates that during the execution of the current thread, the required resources are not obtained after a long wait and are marked as Blocked by the container's thread manager, it can be understood as a thread waiting for resource timeout.
- Waiting for monitor entry and in Object. wait (): Monitor is the main means in Java to implement mutual exclusion and collaboration between threads. It can be regarded as the Lock of objects or classes. Each object has only one monitor. From 1, we can see that each Monitor can only be owned by one Thread at a specific time. This Thread is "Active Thread", while other threads are "Waiting Thread ", wait in the "Entry Set" and "Wait Set" Queues respectively. In "Entry Set", the Waiting thread status is "Waiting for monitor entry", and in "Wait Set", the Waiting thread status is "in Object. wait ()".
Figure 1 A Java Monitor
Comprehensive demonstration 2: W Aiting on condition And TIMED_WAITINGExample: "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 <0x00000000acd84de8>(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)"
TIMED_WAITING (parking)"Timed_waiting indicates the waiting state, but the time is specified here. After the specified time is reached, the waiting state is automatically exited. parking indicates that the thread is suspended. 2)"
Waiting on condition"Needs to be associated with the"
Parking to wait for <0x00000000acd84de8>(A java. util. concurrent. SynchronousQueue $ TransferStack. First, this thread must wait for a condition to wake itself up. Secondly, SynchronousQueue is not a queue, but a mechanism for transferring information between threads. When we put an element into SynchronousQueue, there must be another thread waiting for the task to be handed over, therefore, this is the condition that the thread is waiting. 3) Nothing else can be seen.
Comprehensive demonstration 3: in Obejct. wait ()And TIMED_WAITING
Example: "RMI RenewClean-[172.16.5.19: 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 <0x00000000aa672478> (a java. lang. ref. ReferenceQueue $ Lock)At java. lang. ref. ReferenceQueue. remove (ReferenceQueue. java: 118 )-
Locked <0x00000000aa672478> (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)In this example, the thread enters the waiting state because java. lang. Object. wait (long timeout) is called.
2) The waiting thread status in "Wait Set" is"
In Object. wait ()". When the thread obtains 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 to be synchronized, drop Monitor and enter the "Wait Set" queue. Only when other threads call y () or notifyAll () on this object, the threads in the "Wait Set" queue get the opportunity to compete, but only one thread gets the Monitor of the object, restore to running state.
3) RMI RenewClean is part of DGCClient. DGC refers to Distributed GC, that is, Distributed garbage collection.
4) Note that
Locked <0x00000000aa672478>, After
Waiting on <0x000000000000aa672478>To Lock the object and wait for the same object, see the following code implementation: static private class Lock {}; private lock Lock = new Lock (); public Reference <? Extends T> remove (long timeout) {synchronized (lock) {Reference <? Extends T> r = reallyPoll (); if (r! = Null) return r; for (;) {lock. wait (timeout); r = reallyPoll ();...... } That is, when the thread is being executed, synchronized is used to obtain the Monitor of this object (corresponding
Locked <0x00000000aa672478>); When the lock. wait (timeout); is executed, the thread gives up the Monitor ownership and enters the "Wait Set" Queue (corresponding
Waiting on <0x000000000000aa672478>). 5) The stack information shows that remote references to remote objects is being cleared. The referenced lease is reached, and distributed garbage collection is being cleared one by one.
Reference resources:1) CUBRID, 2012, How to Analyze Java Thread Dumps; 2) iteye, 2012, full analysis of Virtual Machine stack; 3) iteye, 2008, How to Analyze Java Virtual Machine deadlock; 4) csdn, 2012. Introduction and explanation of some common threads generated during JVM running in java stack dump; 5) 2009, analysis of Java thread dump; 6) Analysis of jiacheo, 2012, and tomcat thread dump; Spymemcached related articles: 1) spymemcached useNagle problem and TCP/IP delay data sending 2) spymemcached: the feature of Auto-Reconnect when an mc node times out for more than 998 consecutive times. 3) implementation of Multiget hole: spymemcached 1) 55 Best Practices Series: MongoDB Best Practices)
2) 55 Best Practices Series: Logging Best Practices () 3) Best Practices Series: front-end code standards and best practices) One image is given: