Java Concurrent and Parallel GC

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

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

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


I am using JVM 6.

Asked by: Miranda317 | Posted: 28-01-2022

Answer 1

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


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

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

Edit: 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.

Answered by: Rafael160 | Posted: 01-03-2022

Answer 2

java/JDK 6 GC tuning : This is from SUN (now Oracle). The full stuff.

Also, see

Answered by: Anna883 | Posted: 01-03-2022

Answer 3

This blog entry has a nice breakdown of the different collectors, and which options are valid:

Answered by: Brooke359 | Posted: 01-03-2022

Answer 4

Java GC tuning is basically a dark art, but in my application (runs with a 50+GB heap, and 16 physical cores) the ConcMarkSweep collector resulted in a 3x speedup over the -server default, and a 2.2x speedup over ParallelOldGC.

If you aren't sharing the machine with other processes (so idle cores are just wasted) use the ConcMarkSweepGC.

Answered by: Emily657 | Posted: 01-03-2022

Answer 5

ParNew is the default young generation collector when CMS is used.You just have to specify -XX:+UseConcMarkSweepGC to use CMS and ParNew will be used by default. CMS is a good collector if avoiding GC jitters is of higher priority but if throughput is more important for eg for a batch like job the default SUN parallel collector does a better job.

Answered by: Kevin830 | Posted: 01-03-2022

Answer 6

You cannot enable two GC options at the same time. I would suggest you to use CMS which is better than and next generation GC compare to UseParNewGC. and if you use Java 1.7 or later and heap size is relatively bigger (like > 4GB) consider using G1.

Answered by: Justin816 | Posted: 01-03-2022

Similar questions

garbage collection - How to reduce java concurrent mode failure and excessive gc

In Java, the concurrent mode failure means that the concurrent collector failed to free up enough memory space form tenured and permanent gen and has to give up and let the full stop-the-world gc kicks in. The end result could be very expensive. I understand this concept but never had a good comprehensive understanding of A) what could cause a concurrent mode failure and B) what's the solution?.

garbage collection - Java CMS GC: can a minor GC occur between final remark and concurrent sweep?

Final remark ensures that all live objects are marked. Concurrent sweepremoves garbage. My assumption is that JVM ensures that minor gc would not run between final remark phase and concurrent sweep phase otherwise there's another remark to be performed in order to track objects that were just promoted to the old gc. Is my assumption correct?

java - Illegal attempt to associate a collection with two open sessions

I'm trying to add a pojo to a collection in another pojo. I'm sure I'm making a really stupid mistake somewhere along the lines but I can't figure out how to solve it. I have a pojo LookupTable which contains a list of Columns: public class LookupTable { private long id; // More properties go here... private List<Column> columns; public void addColumn(Column column) { this.columns...

java - Printing out items in any Collection in reverse order?

I have the following problem in my Data Structures and Problem Solving using Java book: Write a routine that uses the Collections API to print out the items in any Collection in reverse order. Do not use a ListIterator. I'm not putting it up here because I want somebody to do my homework, I just can't seem to understand exactly what it is asking for me to code! W...

java - How do I bind collection attributes to a form in Spring MVC

I'm trying to bind one of my model objects to the fields of a form, using Spring-MVC. Everything works fine, except that one of the attributes of the model object is an unordered collection. Doing something like <c:forEach items="${m.items}" var="i" varStatus="itemsRow"> <form:input path="items[${itemsRow.index}]"/> </c:forEach> <form:errors path="items" />

java - Best Collection To Use?

Does using final for variables in Java improve garbage collection?

Today my colleagues and me have a discussion about the usage of the final keyword in Java to improve the garbage collection. For example, if you write a method like: public Double doCalc(final Double value) { final Double maxWeight = 1000.0; final Double totalWeight = maxWeight * value; return totalWeight; } Declaring the variables in the method final

generics - Java: How to create a collection of a specific parent type and not its subtypes?

I am learning Java for a test (tomorrow) and am wondering about a question that will probably never come up but has got me curious. Is it possible to create a new collection class such as a list or something that can hold only a specific type and not its sub-types? Would I use generics to achieve this goal?

java - Can Hibernate return a collection of result objects OTHER than a List?

Does the Hibernate API support object result sets in the form of a collection other than a List? For example, I have process that runs hundreds of thousands of iterations in order to create some data for a client. This process uses records from a Value table (for example) in order to create this output for each iteration. With a List I would have to iterate through the entire list in order to find a certa...

java - JPA map collection of Enums

Is there a way in JPA to map a collection of Enums within the Entity class? Or the only solution is to wrap Enum with another domain class and use it to map the collection? @Entity public class Person { public enum InterestsEnum {Books, Sport, etc... } //@??? Collection<InterestsEnum> interests; } I am using Hibernate JPA implementation, but of course would prefer implem...

c# - garbage collection Operation

Can someone please explain me how garbage collection is working? (I'm using C# and Java).

Java: Trouble with Generics & Collection type detection

I have a class called DataSet with various constructors, each specifying a different type of variable. It might look a bit like this: public class DataSet { private HashSet Data; public DataSet( DataObject obj ) { Data = new <DataObject>HashSet(); Data.add( obj ); } public DataSet( ObjectRelationship rel ) { Data = new <ObjectRelationship>HashS...

Still can't find your answer? Check out these amazing Java communities for help...

Java Reddit Community | Java Help Reddit Community | Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)