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

What is the routine of Java online problem troubleshooting?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article introduces you what the java online problem troubleshooting routine is, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Tags: java, troubleshooting, monitor

In a word: java application online problems such as high CPU, memory overflow, IO is too high how to troubleshoot, this article describes in detail for you.

1 introduction

After the java application is launched, there will inevitably be a variety of problems. Generally speaking, the problems will be divided into four categories:

(1) problems related to CPU

(2) memory related problems

(3) problems related to disk and IO

(4) Business code problem.

To solve these problems, how to monitor and troubleshoot online is a necessary skill for a java developer. The troubleshooting routines of these problems will be explained below in conjunction with the java command line tool mentioned earlier.

2 troubleshooting routines for CPU problems

If it is found that the system slows down and the application response slows down, the first thing to check is the use of CPU. Generally, the process occupies too much CPU, so it is necessary to monitor the occupation of CPU. In java applications, CPU is mainly related to the running of threads, so specific to java applications, we need to monitor the running status of threads, corresponding to the command line tool jstack. Therefore, to summarize the problem of excessive CPU usage, you can follow the following routines:

# (1) query ID (PID) top-c # (2) learn the startup parameters of this process ps-ef | grep PID or jinfo-flags PID# (3) print the thread stack information and output the file jstack-l PID > PID.dump# (4) get the hexadecimal number printf "% x\ n" of TID according to the process lookup thread ID (TID) top-H-p PID# (5) TID# (6) combines TID with thread stack information files to find problems-can be viewed directly using a text tool-can be viewed using grep TID-A20 PID.dump-needs to be checked with thread status

For more information on jstack tools and thread status, see the article "java Application Monitoring (3)-have you mastered these command line tools"

3 troubleshooting routines for memory problems

The main memory problem is that OOM (out of memory) occurs when the java application is running, so it is recommended to add several parameters, including-Xloggc:file-XX:+HeapDumpOnOutOfMemoryError-XX:HeapDumpPath=logs/heapdump.hprof-XX:ErrorFile=logs/java_error_%p.log, when the java application starts. In this way, when oom occurs, you can analyze the cause of oom from the file that comes out of dump. Java command-line tools related to memory problems include jmap,jstat, so the troubleshooting routines for memory OOM are as follows:

# (1) find java application process (PID) jps-lvm or top-c # (2) learn the startup parameters of this process (especially-Xms,-Xmx, etc.) ps-ef | grep PID or jinfo-flags PID# (3) confirm memory jmap-heap PID# (4) find large objects that occupy memory jmap-histo:live PID# (5) dump out of the heap file In order to use the tool to analyze jmap-dump:file=./heap.hprof PID# (6) to view GC changes, print jstat-gc PID 1000 # (7) analyze OOM and GC with log file error information and heap files from dump-memory allocation is small, memory is adjusted properly-objects are created frequently and not released, optimization code-young gc frequency is too high Check whether the parameter settings such as-Xmn and-XX:SurvivorRatio are reasonable.

With regard to OOM, the official documentation has notes on OOM (https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/memleaks002.html), which are mainly divided into the following categories:

Java.lang.OutOfMemoryError: Java heap space, the memory footprint of the heap has reached the maximum value set by-Xmx, so it is impossible to create new objects. Simply consider adjusting the-Xmx parameter to solve the problem.

Java.lang.OutOfMemoryError: GC Overhead limit exceeded, which means that the GC has been executing and the java process is running slowly, and this exception is usually thrown, and the space allocated by the java heap is so small that new data cannot be placed in the heap. Consider resizing the heap, and if you want to close this output, you can turn off-XX:-UseGCOverheadLimit with the parameter.

Java.lang.OutOfMemoryError: the Requested array size exceeds VM limit,java application attempts to allocate an array larger than the heap size. If the heap size is 256m, but allocates an array of 512m, it will report an error. Consider resizing the heap or modifying the code

Java.lang.OutOfMemoryError: Metaspace, consider adjusting MaxMetaSpaceSize when the amount of native memory required for class metadata exceeds.

Java.lang.OutOfMemoryError: request size bytes for reason. Out of swap space? This error is reported when the allocation from the native heap fails and the native heap may be nearly exhausted, and you need to check the log to handle it.

Java.lang.OutOfMemoryError: in the non-heap structure of Compressed class space,JVM, there is insufficient storage space for class pointers, so consider using CompressedClassSpaceSize to adjust.

Java.lang.OutOfMemoryError: the local method area of reason stack_trace_with_native_method,JVM is insufficient. If an allocation failure is detected in Java native interface (JNI) or native method, you need to look up the corresponding stack information to query.

4 troubleshooting routines for disk and IO

During the operation of java application, log generation, disk reading and writing and other operations may be involved, such as insufficient disk (too much log output), slow disk reading and writing IO, IO too frequently and so on. In general, the following routines can be used for troubleshooting:

# (1) View disk capacity df-h # (2) check file size and directory size ls-l or directly lldu-h-max-depth=1# (3) check IO and find processes that read and write frequently in IO PIDiotop-d print once per second or iostat-d-x-k print once per second # (4) print thread stack information using stack Troubleshooting IO related code # (5) sometimes if you want to test the read and write speed of a disk (especially a virtual machine), you can use dd# example: test the pure write speed of the data volume mount directory dd if=/dev/zero of=/ data volume directory / test.iso bs=8k count=10000005 business troubleshooting routines

Business problems are mainly related to the logic level of the code, mainly query log output, and whether the method is executed according to the correct logic, so the general troubleshooting routines are as follows:

# (1) Real-time log output query tail-fn 100 log_file# (2) locate the problem grep keyWord log_file# keyword before and after the grep-C n keyWord log_file# keyword based on the log output keyword. N lines # (3) Log files are analyzed using a visual text tool (notepad++,sublime View large files such as EmEditor) # (4) use online tools to directly detect the parameters, return values, exceptions, etc., such as Btrace,arthas.

Combined with java command line tools and online diagnostic tools, it is very convenient to troubleshoot java applications.

On the java online problem troubleshooting routines what is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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

Internet Technology

Wechat

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

12
Report