JVM参数配置

堆内存大小配置
这是我的初始值

public class Test {
			public static void main(String[] args) {
				System.out.println("最大内存"+Runtime.getRuntime().maxMemory()/1024/1024);
				System.out.println("可用内存"+Runtime.getRuntime().freeMemory()/1024/1024);
				System.out.println("已经内存"+Runtime.getRuntime().totalMemory()/1024/1024);
					
			}
}
最大内存882
可用内存58
已经内存59

``
现在我们来配置一下,RunAs里面`
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190127134745857.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzI4NjMxOTM1,size_16,color_FFFFFF,t_70)
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190127135108396.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzI4NjMxOTM1,size_16,color_FFFFFF,t_70)
使用示例:  -Xmx20m -Xms5m  
说明: 当下Java应用最大可用内存为20M, 初始内存为5M。

设置新生代比例参数

public class Test {
public static void main(String[] args) {
byte[] b = null;
for (int i = 0; i < 10; i++) {
b = new byte[1 * 1024 * 1024];
}
//-Xms20m -Xmx20m -Xmn1m -XX:SurvivorRatio=2 -XX:+PrintGCDetails -XX:+UseSerialGC
//说明:堆内存初始化值20m,堆内存最大值20m,新生代最大值可用1m,eden空间和from/to空间的比例为2/1
System.out.println(“最大内存”+Runtime.getRuntime().maxMemory()/1024/1024);
System.out.println(“可用内存”+Runtime.getRuntime().freeMemory()/1024/1024);
System.out.println(“已经内存”+Runtime.getRuntime().totalMemory()/1024/1024);

		}

}

[GC[DefNew: 512K->256K(768K), 0.1263384 secs] 512K->439K(20224K), 0.1423776 secs] [Times: user=0.00 sys=0.00, real=0.14 secs] 
最大内存19
可用内存9
已经内存19
Heap
 def new generation   total 768K, used 392K [0x00000000f9a00000, 0x00000000f9b00000, 0x00000000f9b00000)
  eden space 512K,  26% used [0x00000000f9a00000, 0x00000000f9a22320, 0x00000000f9a80000)
  from space 256K, 100% used [0x00000000f9ac0000, 0x00000000f9b00000, 0x00000000f9b00000)
  to   space 256K,   0% used [0x00000000f9a80000, 0x00000000f9a80000, 0x00000000f9ac0000)
 tenured generation   total 19456K, used 10423K [0x00000000f9b00000, 0x00000000fae00000, 0x00000000fae00000)
   the space 19456K,  53% used [0x00000000f9b00000, 0x00000000fa52dff0, 0x00000000fa52e000, 0x00000000fae00000)
 compacting perm gen  total 21248K, used 2437K [0x00000000fae00000, 0x00000000fc2c0000, 0x0000000100000000)
   the space 21248K,  11% used [0x00000000fae00000, 0x00000000fb061608, 0x00000000fb061800, 0x00000000fc2c0000)
No shared spaces configured.
当去掉前面的参数:只留下日志-XX:+PrintGCDetails -XX:+UseSerialGC

最大内存958
可用内存49
已经内存59
Heap
def new generation total 19008K, used 11254K [0x00000000bce00000, 0x00000000be2a0000, 0x00000000d18a0000)
eden space 16896K, 66% used [0x00000000bce00000, 0x00000000bd8fd8d8, 0x00000000bde80000)
from space 2112K, 0% used [0x00000000bde80000, 0x00000000bde80000, 0x00000000be090000)
to space 2112K, 0% used [0x00000000be090000, 0x00000000be090000, 0x00000000be2a0000)
tenured generation total 42368K, used 0K [0x00000000d18a0000, 0x00000000d4200000, 0x00000000fae00000)
the space 42368K, 0% used [0x00000000d18a0000, 0x00000000d18a0000, 0x00000000d18a0200, 0x00000000d4200000)
compacting perm gen total 21248K, used 2437K [0x00000000fae00000, 0x00000000fc2c0000, 0x0000000100000000)
the space 21248K, 11% used [0x00000000fae00000, 0x00000000fb061608, 0x00000000fb061800, 0x00000000fc2c0000)
No shared spaces configured.

发现没有eden:from:to=8:1:1,这是默认的配置。
配置新生代和老年代的比列

public class Test {
			public static void main(String[] args) {
				byte[] b = null;
				for (int i = 0; i < 10; i++) {
				b = new byte[1 * 1024 * 1024];
				}
				//-Xms20m -Xmx20m -XX:SurvivorRatio=2 -XX:+PrintGCDetails -XX:+UseSerialGC
				//-XX:NewRatio=2
				
				System.out.println("最大内存"+Runtime.getRuntime().maxMemory()/1024/1024);
				System.out.println("可用内存"+Runtime.getRuntime().freeMemory()/1024/1024);
				System.out.println("已经内存"+Runtime.getRuntime().totalMemory()/1024/1024);
					
			}
}
[GC[DefNew: 2727K->1491K(5120K), 0.0056978 secs] 2727K->1491K(18816K), 0.0058141 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 
[GC[DefNew: 4675K->1024K(5120K), 0.0041652 secs] 4675K->1491K(18816K), 0.0042222 secs] [Times: user=0.01 sys=0.00, real=0.01 secs] 
[GC[DefNew: 4124K->1024K(5120K), 0.0143805 secs] 4591K->1491K(18816K), 0.0144341 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 
最大内存18
可用内存14
已经内存18
Heap
 def new generation   total 5120K, used 3228K [0x00000000f9a00000, 0x00000000fa0a0000, 0x00000000fa0a0000)
  eden space 3456K,  63% used [0x00000000f9a00000, 0x00000000f9c27340, 0x00000000f9d60000)
  from space 1664K,  61% used [0x00000000f9f00000, 0x00000000fa000010, 0x00000000fa0a0000)
  to   space 1664K,   0% used [0x00000000f9d60000, 0x00000000f9d60000, 0x00000000f9f00000)
 tenured generation   total 13696K, used 467K [0x00000000fa0a0000, 0x00000000fae00000, 0x00000000fae00000)
   the space 13696K,   3% used [0x00000000fa0a0000, 0x00000000fa114ea8, 0x00000000fa115000, 0x00000000fae00000)
 compacting perm gen  total 21248K, used 2440K [0x00000000fae00000, 0x00000000fc2c0000, 0x0000000100000000)
   the space 21248K,  11% used [0x00000000fae00000, 0x00000000fb062128, 0x00000000fb062200, 0x00000000fc2c0000)
No shared spaces configured.

下面是我默认的

最大内存958
可用内存59
已经内存59
Heap
 def new generation   total 19008K, used 1014K [0x00000000bce00000, 0x00000000be2a0000, 0x00000000d18a0000)
  eden space 16896K,   6% used [0x00000000bce00000, 0x00000000bcefd838, 0x00000000bde80000)
  from space 2112K,   0% used [0x00000000bde80000, 0x00000000bde80000, 0x00000000be090000)
  to   space 2112K,   0% used [0x00000000be090000, 0x00000000be090000, 0x00000000be2a0000)
 tenured generation   total 42368K, used 0K [0x00000000d18a0000, 0x00000000d4200000, 0x00000000fae00000)
   the space 42368K,   0% used [0x00000000d18a0000, 0x00000000d18a0000, 0x00000000d18a0200, 0x00000000d4200000)
 compacting perm gen  total 21248K, used 2437K [0x00000000fae00000, 0x00000000fc2c0000, 0x0000000100000000)
   the space 21248K,  11% used [0x00000000fae00000, 0x00000000fb061578, 0x00000000fb061600, 0x00000000fc2c0000)
No shared spaces configured.
从上可以看出新生代和老年代的比例大约为1:2。

后面持续更新和学习中


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值