Home Java javaTutorial Summary and analysis of JVM tuning techniques

Summary and analysis of JVM tuning techniques

Jan 23, 2017 am 10:15 AM

This is a technical article. If you are looking for articles about GC or adjusting internal purity, please read my other articles. Since this is a summary of JVM tuning, I won’t talk nonsense. The following methods have been collected from various aspects:
1. Upgrade the JVM version. If 64-bit is available, use a 64-bit JVM.​
Basically there is nothing to explain, it is very simple to upgrade the JVM to the latest version. If you are still using JDK1.4 or even an earlier JVM, the first thing you have to do is upgrade. Because the JVM from 1.4->1.5->1.6 is not just a version number upgrade, or just adding a bunch of new language features to it, it is as simple as that. Instead, major improvements have been made to the JVM. Every version upgrade brings huge performance upgrades. Especially when SUN realizes that Java is everything to a confidant (a bit exaggerated, but even the stock number has been changed to JAVA, haha). If you often visit SUN's JVM forum, you will find that there are actually so many problems with the JVM. If you cannot upgrade to 1.6 for various reasons, you can upgrade to the latest version of that version.
2. Choose a correct GC (Gargage Collection).
Because when the JAVA program GCs, the current program will be stopped. Especially during Full GC, it will stay for a long time. Generally for GUI programs, it is difficult to accept (think about when Eclipse is paused). After JAVA5, several types of GC come with it. You can choose the one that suits you. There are four types of Serial Collector, Parallel collector, Concurrent Collector, and Train Collector (obsolete). Parallel collection is used in the latter several times, so it is theoretically more efficient (you are required to have more than 2CUP, but now multi-core is becoming more popular, haha). Tip: After changing the GC type, increase the amount of JVM memory appropriately.
3. Set the memory size correctly. Set the size correctly for each area (young, old, perm) in the JVM heap.
This is the most difficult adjustment, because this adjustment will directly affect the efficiency of GC. And since the types of each program are different, there is no universal data. In addition to a few common rules, you need to use tools (jstat, jvmstat, jconsole, etc.) to adjust carefully. Several commonly used guidelines are mentioned below. Usually use a few parameters to adjust -Xms -Xmx-XX:MaxPermSize.
3.1 Increasing the value of -XX:NewRatio (NewSize/MaxNewSize) will reduce the number of young gcs, but increase the time of old gcs.
3.2 Method to increase normal GC (reduce Full GC). Increase the size of the young area (up to 40%) and oversize the Survivor area. Keep more objects in young gen.
4. Reduce the usage of classes, pay attention to the load and unload of classes, and reduce the number of JSP pages.
Classes are actually objects and will be directly allocated in the perm area. Even Full GC will rarely collect them. JSP will also be allocated to the perm area, with the same effect. If perm is too large and exceeds the XX:MaxPermSize value, an OutOfMemoryError: PermGen space exception will occur. The solution is to increase the -XX:MaxPermSize value.
5. Avoid using -Xnoclassgc
6. If it is an RMI program, pay attention to adjusting the RMI DGC time.
The following are a few things you should pay attention to when writing programs. GC can also be reduced to improve JVM performance.
1. Do not use the System.gc() method.
Because it will generate Full GC.
2. Allocate as few large temporary objects (with short life cycles) as possible
They may be allocated directly to the old area. The old area will only be collected during Full GC.
3. Avoid using the finalize() method.
finalize() will increase the burden on GC, use java.lang.ref instead.

For more articles related to summary and analysis of JVM tuning techniques, please pay attention to the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Apr 19, 2025 pm 04:51 PM

Troubleshooting and solutions to the company's security software that causes some applications to not function properly. Many companies will deploy security software in order to ensure internal network security. ...

How to simplify field mapping issues in system docking using MapStruct? How to simplify field mapping issues in system docking using MapStruct? Apr 19, 2025 pm 06:21 PM

Field mapping processing in system docking often encounters a difficult problem when performing system docking: how to effectively map the interface fields of system A...

How to elegantly obtain entity class variable names to build database query conditions? How to elegantly obtain entity class variable names to build database query conditions? Apr 19, 2025 pm 11:42 PM

When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

How do I convert names to numbers to implement sorting and maintain consistency in groups? How do I convert names to numbers to implement sorting and maintain consistency in groups? Apr 19, 2025 pm 11:30 PM

Solutions to convert names to numbers to implement sorting In many application scenarios, users may need to sort in groups, especially in one...

How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log? How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log? Apr 19, 2025 pm 11:45 PM

Start Spring using IntelliJIDEAUltimate version...

How to safely convert Java objects to arrays? How to safely convert Java objects to arrays? Apr 19, 2025 pm 11:33 PM

Conversion of Java Objects and Arrays: In-depth discussion of the risks and correct methods of cast type conversion Many Java beginners will encounter the conversion of an object into an array...

E-commerce platform SKU and SPU database design: How to take into account both user-defined attributes and attributeless products? E-commerce platform SKU and SPU database design: How to take into account both user-defined attributes and attributeless products? Apr 19, 2025 pm 11:27 PM

Detailed explanation of the design of SKU and SPU tables on e-commerce platforms This article will discuss the database design issues of SKU and SPU in e-commerce platforms, especially how to deal with user-defined sales...

How to elegantly get entity class variable name building query conditions when using TKMyBatis for database query? How to elegantly get entity class variable name building query conditions when using TKMyBatis for database query? Apr 19, 2025 pm 09:51 PM

When using TKMyBatis for database queries, how to gracefully get entity class variable names to build query conditions is a common problem. This article will pin...

See all articles