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 the Linux system views java threads

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly shows you how to view Linux threads in the Linux system. The content is easy to understand and clear. I hope it can help you solve your doubts. Let's take you to study and learn this article.

In the Linux environment, when you find that the java process takes up a lot of CPU resources, and you want to further find out which java thread consumes CPU resources, follow these steps to find out:

(1): check the running status of the threads of the java process through [top-p12377-H]

And generate dump details of Java threads through [jstack 12377 > stack.log]

First use the top command to find out the resource-intensive java process id, as shown in figure: # top

As shown in the figure above, the process id of java is' 52554, and then use the top command to monitor all threads in this process separately:

In the top-p52554-H# top view, you can use the shortcut keys to highlight the top columns in order b and x to find the desired threads. By default, CPU sort, and Shift+ can move the highlighted columns left and right.

As shown in the figure: (at this point, we can see which Java thread has the highest CPU and which thread uses more memory)

As shown in the figure above, all java internal threads under linux actually correspond to a process id, that is, sun jvm on linux maps threads in java programs to operating system processes. We can see that the process id with the highest consumption of CPU resources is' 15417', and this process id corresponds to 'nid' (' n' stands for 'native') in java thread information.

(1) to find out which specific code takes up so much resources, use jstack to type the current stack information into a file, such as stack.log:

Python-c "print hex (9757)" then remember the binary number

Cat stack.log | grep binary number

1. * * jstack\ * * 52554\ *\ * >\ * * stack\ *. Log\ *

Then use the 'jtgrep' script to grab the java thread with process number' 9757'in stack.log:

1jtgrep 9757 stack.log

Among them, 'jtgrep' is a random shell script written by yourself:

1#!/bin/sh

3nid=python-c "" print hex ($1) ""

4grep-I $nid $2

The reason is very simple, that is, after converting '9757' into hexadecimal, the direct grep stack.log; can see that the nid=0x3c39 of the thread that is grep is exactly the hexadecimal representation of 15417.

What are the versions of Linux? the versions of Linux are Deepin, UbuntuKylin, Manjaro, LinuxMint, Ubuntu and so on. Among them, Deepin is one of the best-developed Linux distributions in China; UbuntuKylin is a derivative release based on Ubuntu; Manjaro is a Linux release based on Arch; LinuxMint's default Cinnamon desktop is similar to Windows XP's easy-to-use; Ubuntu is the Linux operating system based on desktop applications.

The above is about "how the Linux system views Java threads". If this article is helpful to you and think it is well written, please share it with your friends to learn new knowledge. if you want to know more about it, please pay more attention to the industry information channel.

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

Development

Wechat

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

12
Report