I have an application that's running on a 24x6 schedule. Currently, after running for a few days, a Full GC is performed automatically - and usually during a busy part of the day, which negatively impacts user response times.
What I'd like to do is force a Full GC - perhaps at midnight each night, during very low usage times - to prevent it from happening during the day. I've tried System.gc(), but it doesn't seem to guarantee when a Full GC will happen, or even if it will. Is there some means of doing this?
Version info:
Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
Java HotSpot(TM) Server VM (build 11.0-b16, mixed mode)
Additionally -
To be more specific, I'm looking more for a technique to use to ensure that a Full GC is going to happen, rather than a simple method/function to call to run it.
At the moment I'm looking at the modification of the percentage threshold used by CMS to determine when a Full GC is required.
Thanks for any help.
jmap -histo:live <PID>
will force Full GC as "side effect" of finding all live objects. You can schedule it to recycle your JVM processes on off-working hours.
Your JVM build 1.6.0_11-b03
is pretty ancient, but jmap
should be supported on all 1.6 HotSpot JVMs.
No.
System.gc()
suggests to the GC that you would like a collection.
Further, there is probably very little garbage generated during the quiet period and that is why calling System.gc()
doesn't do much.
During peak time there is, presumably, more activity and therefore more garbage being generated - hence the need for a collection.
It should be obvious that you cannot defer collection in that simplistic manner. The JVM will collect when it needs to.
You need to look into tuning your GC - if you have stop the world collection happening then you have some issue. This shouldn't really happen on a modern server JVM.
You should look into tuning the CMS collector - this is a pretty good article on the basics of the GC system in Java. In Java 7 there is the new G1GC which may or may not be better.
You should find a way to simulate load conditions and try different GC parameters, the CMS GC has many tuning parameters and configuring it is somewhat of a dark art...
This is a somewhat more involved article on GC tuning and benchmarking.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With