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 optimize JVM memory

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly explains "how to optimize JVM memory". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to optimize JVM memory.

Install the MAT (MemoryAnalyzer Tool) plugin on Eclipse and link to the official website (https://wiki.eclipse.org/MemoryAnalyzer)

The steps are as follows:

Click Help,Install New Soft and the following Install interface appears: then we click ADD and fill in the pop-up box with the address of the Mat plug-in: http://download.eclipse.org/mat/1.8/update-site/.

Click Select All, click Next, and then continue to confirm that you can install it. After installation, you need to restart Eclipse.

Analysis command

/ /-Xms8m-Xmx8m-XX:+PrintGCDetails// print garbage collection information / /-Xms8m-Xmx32m-XX:+HeapDumpOnOutOfMemoryError// generate memory snapshot file to view error message package com.shi.jvm;import java.util.ArrayList;import java.util.List / * Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "main" * @ author shiye * GC tracking:-verbose:gc-XX:+PrintGCDetails print GC details-XX:+PrintGCTimeStamps print CG occurrence timestamp-Xloggc:log/gc.log specifies the location of the GC log Use file output to help developers analyze the problem heap:-XX:+PrintHeapAtGC prints heap information after each GC-XX:+TraceClassLoading monitor class loading-XX:+PrintClassHistogram after pressing Ctrl+Break Print class information:-Xmx-Xms specifies maximum heap and minimum heap-Xmx20m-Xms5m-Xmn sets the size of the new generation-the ratio of the XX:NewRatio new generation (eden+2*s) to the old age (excluding the permanent zone) Cenozoic: old age = 1:4 That is, the younger generation occupies the heap 1 XX:SurvivorRatio 5-XX:SurvivorRatio sets the ratio of two Survivor zones to eden Survivor: eden=2:8 That is, the result of a Survivor occupying the younger generation is 10-Xmx20m-Xms20m-Xmn1m-XX:+PrintGCDetails: Exception in thread "main" [Full GC (Ergonomics) java.lang.OutOfMemoryError: GC overhead limit exceeded [PSYoungGen: 512K-> 0K (1024K)] [ParOldGen: 18595K-> 517K (18944K)] 19107K-> 517K (19968K), [Metaspace: 2625K-> 2625K (1056768K)], 0.0077164 secs] [Times: user=0.00 sys=0.00 Real=0.01 secs] at java.lang.Integer.toString (Unknown Source) at java.lang.String.valueOf (Unknown Source) at com.shi.jvm.OOMTest.main (OOMTest.java:58)-path to export heap to file-XX:+HeapDumpPath export OOM when XX:+HeapDumpOnOutOfMemoryError OOM- Xmx20m-Xms5m-XX:+HeapDumpOnOutOfMemoryError-XX:HeapDumpPath=d:/a.dump XX:OnOutOfMemoryError in OOM Execute a script "- XX:OnOutOfMemoryError=D:/tools/jdk1.7_40/bin/printstack.bat% p" when the program OOM, the dump of the thread will be generated in D:/a.txt that can send mail when OOM Even the summary of the restart program: adjust the size of the Cenozoic and the surviving generation according to the actual situation. It is officially recommended that the Cenozoic era occupies the heap of 3max 8, the surviving generation accounts for the Cenozoic generation 1max 10 in the OOM, remember Dump out of the heap. Make sure you can troubleshoot the on-site problem stack:-XX:PermSize-XX:MaxPermSize sets the initial space and maximum space of the permanent zone, they say How many types a system can hold-Xss usually only a few hundred K determines the depth of the function call, each thread has an independent stack space local variable, Parameters are assigned on the stack * * / public class OOMTest {public static void main (String [] args) {List list = new ArrayList () Int I = 0; while (true) {/ / public native String intern (); list.add (String.valueOf (iTunes +). Intern ());}

At this point, I believe that everyone on the "JVM memory optimization how to do" have a deeper understanding, might as well to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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