Java并发和并行GC [英] Java Concurrent and Parallel GC

查看:470
本文介绍了Java并发和并行GC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

本文此处建议使用 -XX:+ UseParNewGC 使用并发GC启用并行年轻代GC。

This article here suggests to use -XX:+UseParNewGC "To enable a parallel young generation GC with the concurrent GC".

我的困惑是,为了启用并行和并发GC,我应该

My confusion is that in order to enable both parallel and concurrent GC, should I


  • 使用 -XX:+ UseParNewGC

  • 同时使用 -XX:+ UseParNewGC -XX:+ UseConcMarkSweepGC

  • use -XX:+UseParNewGC or
  • use both -XX:+UseParNewGC and -XX:+UseConcMarkSweepGC ?

我使用JVM 6。

推荐答案

因为你链接的文档是一个1.4.2虚拟机,这是我假设你使用(JVM 5和6行为不同)。

Since the document you linked was for a 1.4.2 VM that's what I'll assume you're using (JVMs 5 and 6 behave differently).

http:/ /java.sun.com/docs/hotspot/gc1.4.2/


如果使用-XX:+ UseConcMarkSweepGC
命令行然后标志
UseParNewGC也设置为true如果
没有另外在
命令行上显式设置

if -XX:+UseConcMarkSweepGC is used on the command line then the flag UseParNewGC is also set to true if it is not otherwise explicitly set on the command line

所以答案是你只需要使用-XX:+ UseConcMarkSweepGC,它将启用并行收集器与并行年轻代收集器。

So the answer is you only need to use -XX:+UseConcMarkSweepGC and it will enable the concurrent collector with the parallel young generation collector.

编辑:对于Java 6,相同的标志(-XX:+ UseConcMarkSweepGC)启用并发收集器。你想要的收集器的选择取决于几件事情,你应该测试不同的配置。但有一些非常一般的指导方针。如果你有一个单处理器,单线程机器那么你应该使用串行收集器(默认为一些配置,可以显式启用与-XX:+ UseSerialGC)。对于您的工作负载基本上受CPU限制的多处理器计算机,请使用并行收集器。如果使用-server标志,则默认情况下启用它,或者可以使用-XX:+ UseParallelGC显式启用它。如果您希望GC使用更多的总CPU时间,并且您拥有多个CPU,那么可以使用并发收集器(-XX:+ UseConcMarkSweepGC)使GC暂停时间更短。请注意,对于给定的工作负载,并发收集器往往需要为JVM分配的RAM大于串行或并行收集器,因为可能会发生一些内存碎片。

for Java 6, the same flag (-XX:+UseConcMarkSweepGC) enables the concurrent collector. The choice of collector you want depends on a few things, and you should test different configurations. But there are some very general guidelines. If you have a single processor, single thread machine then you should use the serial collector (default for some configurations, can be enabled explicitly for with -XX:+UseSerialGC). For multiprocessor machines where your workload is basically CPU bound, use the parallel collector. This is enabled by default if you use the -server flag, or you can enable it explicitly with -XX:+UseParallelGC. If you'd rather keep the GC pauses shorter at the expense of using more total CPU time for GC, and you have more than one CPU, you can use the concurrent collector (-XX:+UseConcMarkSweepGC). Note that the concurrent collector tends to require more RAM allocated to the JVM than the serial or parallel collectors for a given workload because some memory fragmentation can occur.

这篇关于Java并发和并行GC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆