Selecting a Garbage Collector in Java


From Java 5 onwards an improvement is made in Java by selecting the Garbage Collector (GC)
based on the class of the machine on which the application is run.

Serial Collector

 The serial collector uses a single thread to perform all garbage collection work, which makes it relatively efficient since there is no communication overhead between threads. Suited for single processor servers.

-XX:+UseSerialGC.

  
Parallel Collector

Known as the throughput collector performs minor collections in parallel, which can significantly reduce garbage collection overhead.Suited for medium- to large-sized data sets that are run on multiprocessor or multi-threaded hardware.

-XX:+UseParallelGC.

 New: parallel compaction is a feature introduced in J2SE 5.0 update 6 and enhanced in Java SE 6 that allows the parallel collector to perform major collections in parallel. Without parallel compaction, major collections are performed using a single thread, which can significantly limit scalability. Parallel compaction is enabled by adding the option -XX:+UseParallelOldGCto the command line. 

Concurrent Collector

Performs most of its work concurrently (i.e., while the application is still running) to keep garbage collection pauses short.For medium- to large-sized data sets for which response time is more important than overall throughput

-XX:+UseConcMarkSweepGC.

 


Selecting a collector 
Unless your application has rather strict pause time requirements, first run your application and allow the VM to select a collector.

If the application has a small data set (up to approximately 100MB), then

·         Select the serial collector with -XX:+UseSerialGC.

If the application will be run on a single processor and there are no pause time requirements

·         Let the VM select the collector, or
·         Select the serial collector with -XX:+UseSerialGC.

If (a) peak application performance is the first priority and (b) there are no pause time requirements or pauses of one second or longer are acceptable,

·         Let the VM select the collector, or
·         Select the parallel collector with -XX:+UseParallelGC and (optionally) enable parallel compaction with -XX:+UseParallelOldGC.

If response time is more important than overall throughput and garbage collection pauses must be kept shorter than approximately one second

·         The concurrent collector with -XX:+UseConcMarkSweepGC. If only one or two processors are available, consider using incremental mode, described below.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s