Jstack tool introduction, jstack Tool

Source: Internet
Author: User

Jstack tool introduction, jstack Tool

I. Application scenarios

When a java application's CPU usage is relatively high or reaches 100% or above, you need to analyze where the code is faulty. In this case, you can use the jstack command

Ii. How to Use

First, use the command ps-ef | grep keyword to find the application process number, which is expressed by PID.

Run the following command to export the current stack:

Jstack 23000> 1.log (23000 is the process number and is redirected to the 1. log File)

 

Find the thread number with the highest cpu usage. There are many threads in a process (23000 is the process number)

 

Run the following command:

Ps-mp 23000-o THREAD, tid

 

The following result is displayed:

USER % CPU PRI SCNT WCHAN USER SYSTEM TID

App 2.0 19-n_tty _--24876

App 2.0 19-futex _--24879

App 1.9 19-futex _--24882

App 1.9 19-futex _--24885

App 1.9 19-futex _--24888

App 0.0 19-futex _--24916

App 97.3 19---24917

App 0.0 19-futex _--24918

App 0.0 19-futex _--24919

App 0.0 19-futex _--24920

App 0.0 19-futex _--24921

24917 of thread usage is found to be 97.3

 

Use the linux Command Line Tool

Printf '% x' 24917

Convert the 10th 24917 to the 16th 6155, because the thread numbers in the stack are represented in hexadecimal notation.

 

Vi 1. log into Stack log search/6155 results:

 

"ChangeService" prio = 10 tid = 0x00007f5158101000 nid = 0x6155 runnable [0x00007f4f92dec000]

Java. lang. Thread. State: RUNNABLE

At com.xxx.service.impl.ChangeServiceImpl.exe cute (ChangeServiceImpl. java: 115)

At java. util. concurrent. Executors $ RunnableAdapter. call (Executors. java: 471)

At java. util. concurrent. FutureTask. run (FutureTask. java: 262)

At java. util. concurrent. ThreadPoolExecutor. runWorker (ThreadPoolExecutor. java: 1145)

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

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

 

We found that the code here may be faulty. Through locating, we found that an endless loop was written here, leading to a high cpu usage.

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.