当前位置:网站首页>JVM parameter configuration details
JVM parameter configuration details
2022-07-25 15:20:00 【Literary youth learn programming】
1. Common parameter configuration
- -XX:+PrintGC Every time a trigger GC When printing related logs
- -XX:+UseSerialGC Serial recovery
- -XX:+PrintGCDetails More detailed GC journal
- -Xms Initial value of pile
- -Xmx Maximum heap availability
- -Xmn Maximum usable value of the new generation reactor
- -XX:SurvivorRatio For setting up the Cenozoic eden Space and from/to The proportion of space .
- -XX:NewRatio Allocate the proportion of new generation and old generation 1:2
- Including -XX:SurvivorRatio=eden/from=den/to
summary : In practice , We can directly equal the initial heap size to the maximum heap size , This advantage is to reduce the number of garbage collection when the program is running , To improve efficiency .
2. Heap memory size configuration
Examples of use : -Xmx20m -Xms5m
explain : The present Java The maximum available memory of the application is 20M, The initial memory is 5M
// byte[] b = new byte[4 * 1024 * 1024]; // System.out.println(" Allocated 4M Space to array "); System.out.print(" Maximum memory "); System.out.println(Runtime.getRuntime().maxMemory() / 1024.0 / 1024 + "M"); System.out.print(" Available memory "); System.out.println(Runtime.getRuntime().freeMemory() / 1024.0 / 1024 + "M"); System.out.print(" Memory used "); System.out.println(Runtime.getRuntime().totalMemory() / 1024.0 / 1024 + "M"); |
3. Set the Cenozoic scale parameters
Examples of use :-Xms20m -Xmx20m -Xmn1m -XX:SurvivorRatio=2 -XX:+PrintGCDetails -XX:+UseSerialGC
explain : Heap memory initialization value 20m, Maximum heap memory 20m, New generation maximum available 1m,eden Space and from/to The proportion of space is 2/1
Examples of use : -Xms20m -Xmx20m -XX:SurvivorRatio=2 -XX:+PrintGCDetails -XX:+UseSerialGC
4. Set the proportion parameters of the new generation and the old generation
-XX:NewRatio=2
explain : Heap memory initialization value 20m, Maximum heap memory 20m, New generation maximum available 1m,eden Space and from/to The proportion of space is 2/1
The proportion of the new generation and the old generation is 1/2
5. The difference between memory overflow and memory leak
Java Memory leak is the failure to clean up memory garbage in time , As a result, the system can no longer provide you with memory resources ( Out of memory );
and Java Memory overflow is when you ask for more memory than the system can give you , The system can't meet the demand , So there's overflow .
out of memory , That's easy to understand , The storage space is not large enough . It's like pouring too much water , It's spilled from the top of the cup .
Memory leak , The principle is , Used memory space is not released in time , Take up memory for a long time , Eventually, there's not enough memory , And there's a memory overflow .
6. actual combat OutOfMemoryError abnormal
Java Heap overflow
The reason for the error : java.lang.OutOfMemoryError: Java heap space Heap memory overflow
terms of settlement : Set heap memory size // -Xms1m -Xmx10m -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError
// -Xms1m -Xmx10m -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError List<Object> listObject = new ArrayList<>(); for (inti = 0; i < 10; i++) { System.out.println("i:" + i); Byte[] bytes = new Byte[1 * 1024 * 1024]; listObject.add(bytes); } System.out.println(" Add success ..."); |
Virtual machine stack overflow
The reason for the error : java.lang.StackOverflowError Stack memory overflow
Stack overflow Generated from recursive calls , Loop traversal will not , But recursive calls are generated in loop methods , Stack overflow can also occur .
terms of settlement : Set thread maximum call depth
-Xss5m Set the maximum call depth
publicclass JvmDemo04 { privatestaticintcount; publicstaticvoid count(){ try { count++; count(); } catch (Throwable e) { System.out.println(" Maximum depth :"+count); e.printStackTrace(); } } publicstaticvoid main(String[] args) { count(); } }
|
7 The difference between memory overflow and memory leak
Java Memory leak is the failure to clean up memory garbage in time , As a result, the system can no longer provide you with memory resources ( Out of memory );
and Java Memory overflow is when you ask for more memory than the system can give you , The system can't meet the demand , So there's overflow .
out of memory , That's easy to understand , The storage space is not large enough . It's like pouring too much water , It's spilled from the top of the cup .
Memory leak , The principle is , Used memory space is not released in time , Take up memory for a long time , Eventually, there's not enough memory , And there's a memory overflow .
边栏推荐
- Maxcompute SQL 的查询结果条数受限1W
- When using jetty to run items, an error is reported: form too large or form too many keys
- Args parameter parsing
- 树莓派入门:树莓派的初始设置
- 6月产品升级观察站
- CMake指定OpenCV版本
- Recommend 10 learning websites that can be called artifact
- 了解一下new的过程发生了什么
- Iframe nested other website page full screen settings
- Spark DF增加一列
猜你喜欢

Use the command to check the WiFi connection password under win10 system

在win10系统下使用命令查看WiFi连接密码

一个程序最多可以使用多少内存?

Implementation of asynchronous FIFO

MySQL installation and configuration super detailed tutorial and simple database and table building method

Simulate setinterval timer with setTimeout

Fast-lio: fast and robust laser inertial odometer based on tightly coupled IEKF

树莓派入门:树莓派的初始设置

用OpenPose进行单个或多个人体姿态估计

Single or multiple human posture estimation using openpose
随机推荐
iframe嵌套其它网站页面 全屏设置
Process control (Part 1)
MeanShift聚类-01原理分析
海缆探测仪TSS350(一)
记一次Yarn Required executor memeory is above the max threshold(8192MB) of this cluster!
SPI传输出现数据与时钟不匹配延后问题分析与解决
打开虚拟机时出现VMware Workstation 未能启动 VMware Authorization Service
Outline and box shadow to achieve the highlight effect of contour fillet
Instance Tunnel 使用
Solve the error caused by too large file when uploading file by asp.net
【JS高级】js之正则相关函数以及正则对象_02
Redis elimination strategy list
Spark-SQL UDF函数
Stored procedure bias of SQL to LINQ
万能通用智能JS表单验证
异步fifo的实现
Cmake specify opencv version
记一次Spark foreachPartition导致OOM
[Android] recyclerview caching mechanism, is it really difficult to understand? What level of cache is it?
从 join on 和 where 执行顺序认识T-sql查询执行顺序