有時,在每兩天一次到每兩週一次之間的某個地方,我的應用程序崩潰在代碼中看似隨機的位置:java.lang.OutOfMemoryError: GC overhead limit exceeded
。如果我谷歌這個錯誤我來this SO question並導致我this piece of sun documentation其中expains:「java.lang.OutOfMemoryError:超出GC開銷限制」中的過長GC時間的持續時間
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.
,告訴我,我的應用程序顯然是花費的總時間的98%,垃圾回收只收回2%的堆。
但什麼時候98%?應用程序運行整個兩週內的98%?最後一毫秒的98%?
我試圖確定一個最佳的方法來實際解決這一問題,而不是僅僅使用-XX:-UseGCOverheadLimit
,但我覺得有必要更好地理解我解決這個問題。
從文檔看,它似乎是整個2周的98%。您是否使用以下標誌啓用GC日誌:-verbose:gc -XX:+ PrintGCDetails XX:+ PrintGCTimeStamps -Xloggc:PATH_FROM_ROOT/gclog.log。很高興看到應用程序運行時間和由於GC而停止的時間。 – JoseK 2010-05-19 12:28:17
GC日誌記錄是一個很好的建議,我會嘗試。 2周的98%似乎不太可能,但你說得對,這是文檔所暗示的。我希望這只是不準確寫作 – 2010-05-20 10:19:06
你有沒有發現98%的時間意義?我的觀點是GC應該在異常發生的時刻佔用98%的應用程序利用率,而不是在2周內。 – 2010-08-25 10:01:52