title: Duration of Excessive GC Time in "java.lang.OutOfMemoryError: GC overhead limit exceeded"
body: <p>Occasionally, somewhere between once every 2 days to once every 2 weeks, my application crashes in a seemingly random location in the code with: <code>java.lang.OutOfMemoryError: GC overhead limit exceeded</code>. If I google this error I come to <a href="https://stackoverflow.com/questions/1393486/what-means-the-error-message-java-lang-outofmemoryerror-gc-overhead-limit-excee">this SO question</a> and that lead me to <a href="http://java.sun.com/javase/technologies/hotspot/gc/gc_tuning_6.html#cms.overhead" rel="nofollow noreferrer">this piece of sun documentation</a> which expains:</p>
  
  <blockquote>
    <p>The parallel collector will throw an OutOfMemoryError if too much time is
    being spent in garbage collection: if more than 98% of the total time is
    spent in garbage collection and less than 2% of the heap is recovered, an
    OutOfMemoryError will be thrown. This feature is designed to prevent
    applications from running for an extended period of time while making
    little or no progress because the heap is too small. If necessary, this
    feature can be disabled by adding the option -XX:-UseGCOverheadLimit to the
    command line.</p>
  </blockquote>
  
  <p>Which tells me that my application is apparently spending 98% of the total time in garbage collection to recover only 2% of the heap.</p>
  
  <p>But 98% of what time? 98% of the entire two weeks the application has been running? 98% of the last millisecond? </p>
  
  <p>I'm trying to determine a best approach to actually solving this issue rather than just using <code>-XX:-UseGCOverheadLimit</code> but I feel a need to better understand the issue I'm solving.</p>