Java thread stack trace Jstack Chapter

Source: Internet
Author: User
Tags stack trace

1.Jstack Usage Introduction

This command prints a stack trace of the Java thread, knowing which threads are blocked or waiting to find reasons such as thread deadlock

Usage:

Common options:

-F      当’jstack [-l] pid’没有相应的时候强制打印栈信息-l      长列表. 打印关于锁的附加信息,例如属于java.util.concurrent的ownable synchronizers列表.-m     打印java和native c/c++框架的所有栈信息.常用参数:core 将被打印信息的core dump文件remote-hostname-or-IP 远程debug服务的主机名或ipserver-id 唯一id,假如一台主机上多个远程debug服务id    需要被打印配置信息的java进程id,可以用jps查询
Types of 2.tomcat thread states

1. Thread status "waiting on condition"
It indicates that it is waiting for another condition to happen, to wake itself up, or simply that it is called sleep (N).
At this point the thread state is roughly the following:
Java.lang.Thread.State:WAITING (parking): Always wait for that condition to happen;
Java.lang.Thread.State:TIMED_WAITING (parking or sleeping): timed, that condition does not come, also will wake themselves regularly.
If a large number of threads are in "waiting on condition":
Maybe they're running. To obtain third-party resources, especially third-party network resources, delays in obtaining response, resulting in a large number of threads into the waiting state.
So if you find that there are a lot of threads in wait on condition, looking from the thread stack, waiting for the network to read and write, this could be a symptom of a network bottleneck, because the network congestion causes the thread to fail to execute.

Example 1: Timed, the condition does not come, will also wake themselves regularly.

"ContainerBackgroundProcessor[StandardEngine[Catalina]]" daemon prio=10 tid=0x00007f67a419a800 nid=0x4655 waiting on condition [0x00007f679a3fd000]   java.lang.Thread.State: TIMED_WAITING (sleeping)        at java.lang.Thread.sleep(Native Method)        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1510)        at java.lang.Thread.run(Thread.java:745)

Example 2: Always waiting for that condition to happen

"Http-nio-8080-exec-1" daemon prio=10 tid=0x00007f677ca95800 nid=0x46a8 waiting on condition [0x00007f679a47e000] java. Lang. Thread.State:WAITING (parking) at Sun.misc.Unsafe.park (Native Method)-Parking to wait for <0x00000007 A0399b28> (a java.util.concurrent.locks.abstractqueuedsynchronizer$conditionobject) at Java.util.concurrent.loc Ks. Locksupport.park (locksupport.java:186) at java.util.concurrent.locks.abstractqueuedsynchronizer$ Conditionobject.await (abstractqueuedsynchronizer.java:2043) at Java.util.concurrent.LinkedBlockingQueue.take ( linkedblockingqueue.java:442) at Org.apache.tomcat.util.threads.TaskQueue.take (taskqueue.java:104) at Org.ap Ache.tomcat.util.threads.TaskQueue.take (taskqueue.java:32) at Java.util.concurrent.ThreadPoolExecutor.getTask (        threadpoolexecutor.java:1068) at Java.util.concurrent.ThreadPoolExecutor.runWorker (threadpoolexecutor.java:1130) At java.util.concurrent.threadpoolexecutor$Worker.run (threadpoolexecutor.java:615) at Org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run ( taskthread.java:61) at Java.lang.Thread.run (thread.java:745)

1) The timed_waiting in "timed_waiting (parking)" refers to the wait state, but this specifies the time, which automatically exits the wait state after the specified time, and parking the thread is suspended.
2) "Waiting on condition" needs to be in the stack with "parking to wait for <0x00000000acd84de8> (a Java.util.concurrent.synchronousqueue$transferstack) "in combination. First of all, this thread must be waiting for a certain condition to happen, to wake itself up. Second, Synchronousqueue is not a queue, just a mechanism for transferring information between threads, and when we put an element into synchronousqueue, there must be another thread waiting to accept the handover, so this is the condition that this thread is waiting for.

Example 3

"RMI RenewClean-[10.24.189.110:1919]" daemon prio=10 tid=0x00007f6764ee1000 nid=0x4764 in Object.wait() [0x00007f67859b9000]   java.lang.Thread.State: TIMED_WAITING (on object monitor)        at java.lang.Object.wait(Native Method)        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)        - locked <0x00000007a1bca328> (a java.lang.ref.ReferenceQueue$Lock)        at sun.rmi.transport.DGCClient$EndpointEntry$RenewCleanThread.run(DGCClient.java:535)        at java.lang.Thread.run(Thread.java:745)

Example 4

"Timer-8" daemon prio=10 tid=0x00007f676c032800 nid=0x5b7d in Object.wait() [0x00007f6785833000]   java.lang.Thread.State: TIMED_WAITING (on object monitor)        at java.lang.Object.wait(Native Method)        at java.util.TimerThread.mainLoop(Timer.java:552)        - locked <0x00000007b47c7630> (a java.util.TaskQueue)        at java.util.TimerThread.run(Timer.java:505)

2. The thread status is "Waiting for monitor entry":
means that it is waiting to enter a critical section, so it waits in the "Entry Set" queue.
At this point the thread state is generally Blocked:
Java.lang.Thread.State:BLOCKED (on object monitor)

3. If a large number of threads are in "Waiting for Monitor entry":
A global lock may be blocking a large number of threads.
If the thread dump file that is printed in a short time reflects that over time, the waiting for monitor entry threads are increasing and there is no tendency to decrease, which may mean that some threads stay in the critical section for too long, so that more and more new threads are unable to enter the critical section.

3. Example Operation:

[Email protected] conf]# JPS

13886 Jps21147 Application13614 Bootstrap
[[email protected] conf]# jstack 13614|grep "java.lang.Thread.State" |grep parking java.lang.Thread.State: Waiting (parking) Java.lang.Thread.State:WAITING (parking) Java.lang.Thread.State:WAITING (parking) Java.lang.Thre Ad. State:waiting (parking) Java.lang.Thread.State:WAITING (parking) Java.lang.Thread.State:WAITING (parking) java.la Ng.   Thread.State:WAITING (parking) Java.lang.Thread.State:WAITING (parking) Java.lang.Thread.State:WAITING (parking) Java.lang.Thread.State:WAITING (parking) Java.lang.Thread.State:WAITING (parking) Java.lang.Thread.State:WAITING (p arking) Java.lang.Thread.State:WAITING (parking) Java.lang.Thread.State:WAITING (parking) Java.lang.Thread.State: Waiting (parking) Java.lang.Thread.State:WAITING (parking) Java.lang.Thread.State:WAITING (parking) Java.lang.Thre Ad. State:waiting (parking) Java.lang.Thread.State:WAITING (parking) Java.lang.Thread.State:WAITING (parking) java.la Ng. Thread.State:WAITING (parking) Java.lang.Thread.State:WAITING (parking) Java.lang.Thread.State:WAITING (parking) Java.lang.Thread.Stat E:waiting (parking) Java.lang.Thread.State:WAITING (parking) Java.lang.Thread.State:WAITING (parking) java.lang.t Hread. State:waiting (parking) Java.lang.Thread.State:WAITING (parking) Java.lang.Thread.State:WAITING (parking) java.la Ng.   Thread.State:WAITING (parking) Java.lang.Thread.State:WAITING (parking) Java.lang.Thread.State:WAITING (parking) Java.lang.Thread.State:WAITING (parking) Java.lang.Thread.State:WAITING (parking) Java.lang.Thread.State:WAITING (p arking) Java.lang.Thread.State:WAITING (parking) Java.lang.Thread.State:WAITING (parking) Java.lang.Thread.State: Waiting (parking) Java.lang.Thread.State:WAITING (parking) Java.lang.Thread.State:WAITING (parking) Java.lang.Thre Ad. State:timed_waiting (parking)

[Email protected] conf]# jstack 13614|grep "Java.lang.Thread.State" |grep parking|wc-l
41
The number of Java.lang.Thread.State:WAITING (parking) equals the value of the minimum number of idle threads minsparethread

Check for deadlocks
[[Email Protected]_82_178_redhat ~]# jstack-l-F 7523

Attaching to process ID 7523, please wait...Debugger attached successfully.Server compiler detected.JVM version is 25.60-b23Deadlock Detection:**No deadlocks found**.

Java thread stack trace Jstack Chapter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.