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).

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...