Tomcat Log 中有以下異常
May 31, 2012 11:54:25 AM org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler process SEVERE: Error reading request, ignored java.lang.OutOfMemoryError: GC overhead limit exceeded Exception in thread "http-80-43" java.lang.NullPointerException at java.util.concurrent.ConcurrentLinkedQueue.offer(ConcurrentLinkedQueue.java:273) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler$1.offer(Http11Protocol.java:537) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler$1.offer(Http11Protocol.java:554) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:618) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:619) May 31, 2012 11:55:46 AM org.apache.coyote.http11.Http11Processor process SEVERE: Error processing request java.lang.OutOfMemoryError: GC overhead limit exceeded May 31, 2012 11:56:58 AM org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor processChildren
問題產生原因:
根據sun的說法: "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."
jvm gc行為中超過98%以上的時間去釋放小於2%的堆空間時會報這個錯誤。
處理方法:
1. 在jvm啟動參數中添加 "-XX:-UseGCOverheadLimit",該參數在JDK6中默認啟用("-XX:+UseGCOverheadLimit")。
調整后的生產環境中使用的參數為:
JAVA_OPTS='-Xms512m -Xmx4096m -XX:MaxPermSize=128m -XX:-UseGCOverheadLimit -XX:+UseConcMarkSweepGC'
2. 檢查是否有使用了大量內存的代碼或死循環
3. 使用jstat命令監控gc行為是否正常
jstat監控gc的命令格式為:
jstat -gcutil [-t] [-h<lines>] <vmid> [<interval> [<count>]]
vmid為JVM進程id,可以用ps -ef 或 jps -lv命令查找。
以下命令為每1秒鍾輸出一次gc狀態,共輸入5次
[root@localhost bin]# jstat -gcutil 7675 1000 5 S0 S1 E O P YGC YGCT FGC FGCT GCT 0.00 0.00 41.98 9.53 99.26 230 0.466 186 24.691 25.156 0.00 0.00 41.98 9.53 99.26 230 0.466 186 24.691 25.156 0.00 0.00 41.98 9.53 99.26 230 0.466 186 24.691 25.156 0.00 0.00 41.98 9.53 99.26 230 0.466 186 24.691 25.156 0.00 0.00 41.98 9.53 99.26 230 0.466 186 24.691 25.156
經過一段時間的觀察,沒有再出現該異常。
參考:
