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 to tune JVM in java

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces the relevant knowledge of how to tune JVM in java, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this article on how to tune JVM in java. Let's take a look at it.

The introduction of JVM enables the Java language to run on different platforms without recompiling. However, during the testing or operation of the program before launch, there will be all kinds of problems about JVM. For example, the CPU load is too high, the request delay, the tps is reduced, and even there is a memory leak, and the content leads to a system crash and so on. Therefore, it is necessary to tune the JVM to promote the normal operation of the program under the premise of higher user experience and running efficiency.

Observe memory release, collection class check, object tree.

You can view heap space allocation (younger generation, older generation, persistent generation allocation).

Provide real-time garbage collection. Garbage monitoring (monitoring recycling for a long time).

View in-heap classes, object information: quantity, type, etc.

View the object reference.

With the ability to view heap information, we can generally solve the following problems smoothly:

-- whether the size division of the older generation and the younger generation is reasonable

-- memory leak

-whether the setting of garbage collection algorithm is reasonable

Thread information monitoring: number of system threads.

Thread status monitoring: what state each thread is in.

Dump thread details: view the internal operation of the thread deadlock check.

Problem 1: memory leak checking

Memory leakage is a relatively common problem, and the solution is also more general, here we can focus on it, while the thread, hot issues are specific analysis of specific problems.

Memory leakage can generally be understood as the misuse of system resources (resources, heaps, stacks, threads, etc.), resulting in the use of resources can not be recycled (or not recycled), resulting in new resource allocation requests can not be completed, resulting in a system error.

Memory leaks do great harm to the system because it can directly cause the system to crash.

It needs to be distinguished that there is a difference between memory leaks and system overload, although the end result may be the same. A memory leak is an error caused by the non-recovery of used resources, while the system is overloaded because the system really does not have that many resources to allocate (other resources are in use).

Solution:

This way is also relatively easy to solve, generally according to the comparison before and after garbage collection, at the same time according to the object reference (common collection object reference) analysis, basically can find the leak point.

Problem 2: permanent generation is occupied

Exception: java.lang.OutOfMemoryError: PermGen space

Description: Perm space is full. An exception that is thrown when storage space cannot be allocated for a new class. This exception did not exist before, but it is more common today because of the large number of Java reflections. The main reason is that a large number of classes generated by dynamic reflection are constantly loaded, resulting in a full Perm area.

What's even more frightening is that even if different classLoader uses the same class, it will be loaded, which is equivalent to the same thing. If there are N classLoader, then it will be loaded N times. Therefore, in some cases, this problem is basically regarded as unsolved. Of course, there are not many cases where there are a lot of classLoader and a lot of reflection classes.

Solution:

1.-XX:MaxPermSize=16m

two。 Switch to JDK. Like JRocket.

Problem 3: stack overflow

Exception: java.lang.StackOverflowError

Description: there is no need to say much about this, generally, it is not returned recursively, or caused by a circular call.

Problem 4: thread stack is full

Exception: Fatal: Stack size too small

Description: there is a limit to the space size of a thread in java. After JDK5.0, the value is 1m. The data associated with this thread will be stored in it. But when the thread space is full, the above exception will occur.

Solution: increase the thread stack size. -Xss2m. However, this configuration does not solve the fundamental problem, and it depends on whether there is a leak in the part of the code.

Problem 5: system memory is full

Exception: java.lang.OutOfMemoryError: unable to create new native thread

Explanation: this exception is caused by the operating system not having enough resources to generate this thread. When the system creates a thread, in addition to allocating memory in the Java heap, the operating system itself needs to allocate resources to create the thread. Therefore, when the number of threads is large to a certain extent, there may be space in the heap, but the operating system cannot allocate resources, so this exception occurs.

The more memory allocated to the Java virtual machine, the less remaining resources of the system. Therefore, when the system memory is fixed, the more memory allocated to the Java virtual machine, the less threads the system can generate, which is inversely proportional to the two. At the same time, you can modify-Xss to reduce the space allocated to a single thread, or you can increase the total number of threads produced in the system.

Solution:

1. Redesign the system to reduce the number of threads.

two。 If the number of threads cannot be reduced, reduce the size of a single thread through-Xss. So that more threads can be produced.

This is the end of the article on "how to tune JVM in java". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to tune JVM in java". If you want to learn more, you are welcome to follow 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