1
我正在JSP(JDK 1.6)中開發一個網站並使用apache tomcat7進行託管。有一個網頁提供用戶輸入,建立一個查詢並將它發送到Lucene數據庫(大小爲20GB),並將結果顯示在可下載的文本文件中。但是,該功能無法正常工作,並且在我提交用戶後出現以下異常輸入。java.lang.OutOfMemoryError:Java堆空間 - 如何解決此錯誤?
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error() that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.OutOfMemoryError: Java heap space
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
javax.servlet.ServletException: java.lang.OutOfMemoryError: Java heap space
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:911)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:840)
org.apache.jsp.Getinfo_jsp._jspService(Getinfo_jsp.java:305)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
java.lang.OutOfMemoryError: Java heap space
org.apache.lucene.codecs.lucene42.Lucene42DocValuesProducer.loadNumeric(Lucene42DocValuesProducer.java:180)
org.apache.lucene.codecs.lucene42.Lucene42DocValuesProducer.getNumeric(Lucene42DocValuesProducer.java:146)
org.apache.lucene.index.SegmentCoreReaders.getNormValues(SegmentCoreReaders.java:301)
org.apache.lucene.index.SegmentReader.getNormValues(SegmentReader.java:259)
org.apache.lucene.search.similarities.TFIDFSimilarity.exactSimScorer(TFIDFSimilarity.java:760)
org.apache.lucene.search.PhraseQuery$PhraseWeight.scorer(PhraseQuery.java:285)
org.apache.lucene.search.BooleanQuery$BooleanWeight.scorer(BooleanQuery.java:323)
org.apache.lucene.search.BooleanQuery$BooleanWeight.scorer(BooleanQuery.java:323)
org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:603)
org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:482)
org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:438)
org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:281)
org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:269)
com.cde.sentiment.DataCollection.GetTweets(DataCollection.java:76)
com.cde.sentiment.SentimentCalculation.GenerateOutputFile(SentimentCalculation.java:102)
org.apache.jsp.Getinfo_jsp._jspService(Getinfo_jsp.java:154)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.27 logs.
Apache Tomcat/7.0.27
這裏是上面的異常的堆棧跟蹤
24 Jun, 2013 3:04:35 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/SentimentAnalysisModule] threw exception [javax.servlet.ServletException: java.lang.OutOfMemoryError: Java heap space] with root cause
java.lang.OutOfMemoryError: Java heap space
at org.apache.lucene.codecs.lucene42.Lucene42DocValuesProducer.loadNumeric(Lucene42DocValuesProducer.java:180)
at org.apache.lucene.codecs.lucene42.Lucene42DocValuesProducer.getNumeric(Lucene42DocValuesProducer.java:146)
at org.apache.lucene.index.SegmentCoreReaders.getNormValues(SegmentCoreReaders.java:301)
at org.apache.lucene.index.SegmentReader.getNormValues(SegmentReader.java:259)
at org.apache.lucene.search.similarities.TFIDFSimilarity.exactSimScorer(TFIDFSimilarity.java:760)
at org.apache.lucene.search.PhraseQuery$PhraseWeight.scorer(PhraseQuery.java:285)
at org.apache.lucene.search.BooleanQuery$BooleanWeight.scorer(BooleanQuery.java:323)
at org.apache.lucene.search.BooleanQuery$BooleanWeight.scorer(BooleanQuery.java:323)
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:603)
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:482)
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:438)
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:281)
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:269)
at com.cde.sentiment.DataCollection.GetTweets(DataCollection.java:76)
at com.cde.sentiment.SentimentCalculation.GenerateOutputFile(SentimentCalculation.java:102)
at org.apache.jsp.Getinfo_jsp._jspService(Getinfo_jsp.java:154)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
這將被作爲重複關閉,肯定...無論如何:嘗試查找'-Xmx'選項;這就是增加JVM堆大小的原因。默認情況下,它是64MB。 – fge
你需要知道如何消耗內存。下載Visual VM,安裝所有插件,並在運行Tomcat時將其附加到PID。它會告訴你發生了什麼,並幫助你找出原因。 – duffymo
如果你還沒有,我建議你在64位JVM上運行你的應用程序,因爲你可以給它分配更多的內存(essentailly unlimited)。 32位JVM限制在1200M左右。 – wobblycogs