Garbage Collection

本文探讨了Java中垃圾回收的问题检测与调优方法,包括使用jstat工具监控垃圾回收状态,提供了一套针对大型缓存应用的垃圾回收配置建议,并讨论了分布式缓存环境下垃圾回收的特殊调整。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

13.1 Detecting Garbage Collection Problems
       A full garbage collection event pauses all threads in the JVM. Nothing happens during the pause. If this
pause takes more than a few seconds it will become noticeable.
The clearest way to see if this is happening is to run jstat. The following command will produce a log of
garbage collection statistics, updated each ten seconds.
        jstat -gcutil <pid> 10 1000000


      The thing to watch for is the Full Garbage Collection Time. The difference between the total time for each
reading is the time the system spends time paused. If there is a jump more than a few seconds this will not
be acceptable in most application contexts.

 

13.2 Garbage Collection Tuning
The Sun core garbage collection team has offered the following tuning suggestion for virtual machiens
with large heaps using caching:
java ... -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC
-XX:NewSize=<1/4 of total heap size> -XX:SurvivorRatio=16
The reasoning for each setting is as follows:
• -XX:+DisableExplicitGC - some libs call System.gc(). This is usually a bad idea and could explain
some of what we saw.
• -XX:+UseConcMarkSweepGC - use the low pause collector
• -XX:NewSize=1/4 of total heap size -XX:SurvivorRatio=16

 

13.3 Distributed Caching Garbage Collection Tuning
Some users have reported that cenabling distributed caching auses a full GC each minute. This is an issue
with RMI generally, which can be worked around by increasing the interval for garbage collection. The
effect that RMI is having is similar to a user application calling System.gc() each minute. In the settings
above this is disabled, but it does not disable the full GC initiated by RMI.
The default in JDK6 was increased to 1 hour. The following system properties control the interval.
-Dsun.rmi.dgc.client.gcInterval=60000
-Dsun.rmi.dgc.server.gcInterval=60000
See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4403367 for the bug report and detailed instructions
on workarounds.
Increase the interval as required in your application.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值