java – 如何降低GC中的弱引用处理时间?

前端之家收集整理的这篇文章主要介绍了java – 如何降低GC中的弱引用处理时间?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
目前我面临的问题是我的应用程序偶尔显示出长时间的GC时间,但是这些都只是由于参考处理弱.所以线程停止的时间总是接近弱的ref处理时间.所有其他GC循环均为0.0001秒至0.200秒.

从gc.log(重新格式化):

10388.186: [GC[YG occupancy: 206547 K (306688 K)]10388.186: [Rescan (parallel),0.1095860 secs]10388.295: [weak refs processing,2.0799570 secs] 
 [1 CMS-remark:  2973838K(3853568K)] 3180386K(4160256K),2.1899230 secs] 
 [Times: user=2.51 sys=0.00,real=2.18 secs]
Total time for which application threads were stopped: 2.1906890 seconds

目前我已经有了这些设置.尝试更简单的设置,但没有变化.

-Xms4g
-Xmx4g
-XX:NewSize=128m
-XX:+UseConcMarkSweepGC
-XX:+CMSIncrementalMode
-XX:MaxGCPauseMillis=50
-XX:CMSInitiatingOccupancyFraction=50
-XX:ParallelGCThreads=16
-XX:+DisableExplicitGC

如果我打开NewSize,我最终会遇到长时间的GC循环.该机器有8个内核,不会为应用程序烧录太多的cpu.试图早期和同时运行旧gen GC.

是的,我不能摆脱弱参考用法,因为这是第三方图书馆的一部分.

解决方法

我在“热点 – gc-use”邮件列表中找到了 this message.

简而言之,尝试-XX:ParallelRefProcEnabled开关.

UPDATE

我在Jon Masamitsu的Weblog中发现了一个更好的解释:

6) Parallel reference processing in the low pause collector.

For an application that uses 07002 objects extensively,the GC work to process the Reference objects can be noticeable. It’s not necessarily worse in the low pause collector than in the other collects,but it hurts more (because we’re trying to keep the pauses low). Parallel reference processing is available for the low pause collector but is not on by default. Unless there are tons of Reference Objects,doing the reference processing serially is usually faster. Turn it on with the flag -XX:+ParallelRefProcEnabled if you make extensive use of Reference Objects (most applications don’t).

猜你在找的Java相关文章