search
HomeJavajavaTutorialSummary and analysis of JVM tuning techniques

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
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
How does the JVM manage garbage collection across different platforms?How does the JVM manage garbage collection across different platforms?Apr 28, 2025 am 12:23 AM

JVMmanagesgarbagecollectionacrossplatformseffectivelybyusingagenerationalapproachandadaptingtoOSandhardwaredifferences.ItemploysvariouscollectorslikeSerial,Parallel,CMS,andG1,eachsuitedfordifferentscenarios.Performancecanbetunedwithflagslike-XX:NewRa

Why can Java code run on different operating systems without modification?Why can Java code run on different operating systems without modification?Apr 28, 2025 am 12:14 AM

Java code can run on different operating systems without modification, because Java's "write once, run everywhere" philosophy is implemented by Java virtual machine (JVM). As the intermediary between the compiled Java bytecode and the operating system, the JVM translates the bytecode into specific machine instructions to ensure that the program can run independently on any platform with JVM installed.

Describe the process of compiling and executing a Java program, highlighting platform independence.Describe the process of compiling and executing a Java program, highlighting platform independence.Apr 28, 2025 am 12:08 AM

The compilation and execution of Java programs achieve platform independence through bytecode and JVM. 1) Write Java source code and compile it into bytecode. 2) Use JVM to execute bytecode on any platform to ensure the code runs across platforms.

How does the underlying hardware architecture affect Java's performance?How does the underlying hardware architecture affect Java's performance?Apr 28, 2025 am 12:05 AM

Java performance is closely related to hardware architecture, and understanding this relationship can significantly improve programming capabilities. 1) The JVM converts Java bytecode into machine instructions through JIT compilation, which is affected by the CPU architecture. 2) Memory management and garbage collection are affected by RAM and memory bus speed. 3) Cache and branch prediction optimize Java code execution. 4) Multi-threading and parallel processing improve performance on multi-core systems.

Explain why native libraries can break Java's platform independence.Explain why native libraries can break Java's platform independence.Apr 28, 2025 am 12:02 AM

Using native libraries will destroy Java's platform independence, because these libraries need to be compiled separately for each operating system. 1) The native library interacts with Java through JNI, providing functions that cannot be directly implemented by Java. 2) Using native libraries increases project complexity and requires managing library files for different platforms. 3) Although native libraries can improve performance, they should be used with caution and conducted cross-platform testing.

How does the JVM handle differences in operating system APIs?How does the JVM handle differences in operating system APIs?Apr 27, 2025 am 12:18 AM

JVM handles operating system API differences through JavaNativeInterface (JNI) and Java standard library: 1. JNI allows Java code to call local code and directly interact with the operating system API. 2. The Java standard library provides a unified API, which is internally mapped to different operating system APIs to ensure that the code runs across platforms.

How does the modularity introduced in Java 9 impact platform independence?How does the modularity introduced in Java 9 impact platform independence?Apr 27, 2025 am 12:15 AM

modularitydoesnotdirectlyaffectJava'splatformindependence.Java'splatformindependenceismaintainedbytheJVM,butmodularityinfluencesapplicationstructureandmanagement,indirectlyimpactingplatformindependence.1)Deploymentanddistributionbecomemoreefficientwi

What is bytecode, and how does it relate to Java's platform independence?What is bytecode, and how does it relate to Java's platform independence?Apr 27, 2025 am 12:06 AM

BytecodeinJavaistheintermediaterepresentationthatenablesplatformindependence.1)Javacodeiscompiledintobytecodestoredin.classfiles.2)TheJVMinterpretsorcompilesthisbytecodeintomachinecodeatruntime,allowingthesamebytecodetorunonanydevicewithaJVM,thusfulf

See all articles

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

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function