The GC strategies do not depend on how you coded your application but on the hardware you have.
For instance, if you have only one CPU available, then you should not enable CMS for two reasons :
- it will steal this only CPU time from your application so you will have STW pauses
- It implies overhead to be concurrent, which means your application will be stopped longer
In that case, you should enable SerialGC (or ParallelGC, it does not matter on a single CPU machine).
Now, if you have N
cores available but your application only uses one, you can set -XX:ConcGCThreads=N-1
and -XX:ParallelGCThreads=N-1
(depending on the GC you use) so that the JVM takes full advantage of your hardware.
Note that before setting any flag, you should enable GC logs using -Xloggc:gc.log -XX:+PrintGCDetails
and check after each new configuration that it improved your application response time/throughput.
Source : http://jvm-options.tech.xebia.fr/