title: Is there a way to schedule a Full Garbage Collection in Java?
body: <p>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.</p>
  
  <p>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?</p>
  
  <p>Version info:</p>
  
  <p>Java(TM) SE Runtime Environment (build 1.6.0_11-b03)<BR>
  Java HotSpot(TM) Server VM (build 11.0-b16, mixed mode)</p>
  
  <p>Additionally -</p>
  
  <ul>
  <li>Minor GCs are running, about every 10-15 seconds.  But these are are not freeing up enough RAM to get the app through a full week.  When a Full GC does happen, nearly 50% of the heap is freed.</li>
  <li>In relation to the above, calling System.gc() doesn't seem to mean that any of the  next GCs, will be of the Full form needed to free those large chucks of memory.  Yes, it is enabled (or not disabled, depending on how you read the -XX option).</li>
  <li>I've already played around with several of the CMS GC settings, which has helped greatly, but not solved the problem.  Originally it was throwing OOMs, two to three times a week.</li>
  <li>I want to stop the endless loops of:
  <ul>
  <li>constantly adding to heap space - which can only go on for so long</li>
  <li>constant tuning and testing of GC settings - it is long past the point of diminishing return</li>
  </ul></li>
  <li>I don't want to treat this like an NT machine and bounce it nightly.  There are active user sessions throughout the night, and bouncing the app would mean loosing session data.</li>
  </ul>
  
  <p>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.</p>
  
  <p>At the moment I'm looking at the modification of the percentage threshold used by CMS to determine when a Full GC is required.</p>
  
  <p>Thanks for any help.</p>