JVM monitoring tools --jstack

[Article] Reference: jstack command Experience

1 Introduction

  jstack mainly used to generate the java virtual machine snapshot of the current moment thread.

  A snapshot is a method in the current thread java virtual machine each executing thread stack collection,

  The main purpose is to locate the thread occurs because a long pause, such as inter-thread deadlocks, infinite loop, resulting in a request for a long time waiting for external resources, etc.

2. Basic Usage

  

 2.1 jstack  <pid>

  Output current thread time snapshot of the process of information;

  Generally divided into three parts:

  The first part is a snapshot of the current time information and information of the JVM;

  Example:

    

   The second part of the implementation of a plurality of threads, a thread analysis we select as an example;

  Example:

    

     main: Thread name;

    prio: thread priority;

    os_prio: thread priority;

    tid: thread ID;

    nid: lightweight processes mapped to the Linux system PID, snapshots with hexadecimal, decimal can be converted to be viewed in the system;

  Thread the current action :  

    Typically recorded at the end of the first line of each thread dump;

    Runnable : CPU parameter represents a thread in the competition, likely to be scheduled to run, may also be waiting in the ready;

    Sleeping : Indicates that the Thread.sleep (), the thread goes to sleep;

    ON for condition Condition Waiting [... 0x] : indicates that the thread is blocked primitive blocked , the address in square brackets indicate resources address the waiting thread ; there is no relationship between this and the jvm built-in lock system, which is java.util after jdk5 .concurrent.locks.Condition locking mechanism in the packet;

    Waiting for Monitor entry [... 0x] : represents the thread attempts to acquire a lock built into the waiting area Entry Set, address in square brackets indicate the address of the thread waiting for resources;

    the Object.wait in () [0x ...] : represents the thread calls object.wait (), gave up the built-in lock, entered the waiting area Wait Set, waiting to be awakened , the address in square brackets indicate the address of the thread to give up resources ;

  Thread.State:  

    RUNNABLE: This usually occurs together with thread action runnable;

    BLOCKED (on object monitor): This general operation of the thread waiting for monitor entry appear together, and do not stack endmost method of fixing a call but its thread, as may be modified in various ways synchronized keyword or sync blocks;

    WAITING (on object monitor) or TIMED_WAITING (on object monitor): this general thread action in Object.wait () [0x ...] appear together, and most end of the thread calls the method call stack is at java.lang. Object.wait (Native method), to indicate that call Object.wait () method;

      Further, the WAITING TIMED_WAITING difference is whether the set timeout interrupt, i.e. wait (long timeout) and wait () distinction;

    WAITING (parking) or TIMED_WAITING (parking): typically this operation thread waiting on condition [0x ...] appear together, and the endmost thread call stack call methods generally at sun.misc.Unsafe.park (Native Method );

      Thread blocking is a primitive Unsafe.park use, to be used primarily in java.util.concurrent.locks.AbstractQueuedSynchronizer class, many AQS constructed based synchronization tool, such as ReentrantLock, Condition, CountDownLatch, Semaphore thread into the other will induce status;

      Further, WAITING consistent with the reason of the difference between a third point TIMED_WAITING mentioned;

  Important threads call modification:

    Thread call stack thread dump, in general, will use state resources associated with the lock in the form of additional modifications as the focus of this action and the state of the thread are closely linked, in general, it can be divided into the following categories:

    Locked <0x ...> , said it successfully acquired the built-in lock to become the owner;

    to the wait for Parking <0x ...> , said it was blocked by blocking primitives , usually appear together with the thread action waiting on condition;

    Lock to waiting <0x ...> , said its in Entry Set in wait for a built-in lock , usually waiting for monitor entry and movement thread appear together;

    ON Waiting <0x ...> , which represents the Wait Set waiting to be awakened , generally thread operation in Object.wait () [0x ...] appear together;

  The third part JVM-level information

  Example:

    

 

     VM Thread: virtual machine threads;

    VM Periodic Task Thread: virtual machine task thread;

    JNI global references: JNI global reference number;

2.2 jstack  -F -m  -l <pid>

  -F: force the stack information when printing process is not responding;

  -m: print Java and native C, C ++ stack of information;

  -l: prints additional information about locks

  When using -F -m parameter will detect deadlock, thread dump printed information will include the following information:

  

 

   When using the -l option, the output current thread holds the lock of the type of address and not the show as None:

  

  

Guess you like

Origin www.cnblogs.com/virgosnail/p/11514609.html