Java Options For Garbage Collection
Return to the Java Programming Corner.
JDK 1.4.1 adds some new options to control garbage collection.
The options for server applications should be:
-server -Xms<size> -Xmx<size> -XX:+UseParallelGC -XX:UseAdaptiveSizePolicywhere <size> is the amount of memory your application will use (128m is 128 megabytes, 128 is 128 bytes). These options select the parallel scavenge collector for young generation garbage, and the mark-sweep-compact collector for old generation garbage. Old generation collection is still single threaded but the mark-sweep-compact collector is very efficient.
The options for applications where pauses are undesirable should be:
-server -Xms<size> -Xmx<size> -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:SurvivorRatio=2 -XX:NewRatio=8where <size> is the amount of memory your application will use (128m is 128 megabytes, 128 is 128 bytes). These options select the parallel copying collector for the new generation, and the concurrent mark-sweep collector for the old generation. The new generation collection uses one thread for each processor on the machine. 1/8 of the memory is used for the new generation, and 7/8 for the old generation. The new generation memory is broken into three pieces, 1/16 of the memory is the eden where new objects are created, and the rest of the new generation is stored in two semi spaces.