I have a web application that uses Struts and iBatis. I am running the application inside of a tomcat server within Eclipse. Whenever I run a SELECT
query that returns many rows, I get a java.lang.OutOfMemoryError
. If I limit the amount of rows returned, then it doesn't happen. I have searched on this site for similar issues, and most of the answers talk about increasing the java heap size which I have done in the eclipse.INI
file by setting it to 2048 via -Xmx2048m
. I have also seen some people suggest changing the way in which jdbc handles the result set, but I have been unable to find how to do that using iBatis. Here is what my database settings look like
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="initialSize" value="3" />
<property name="maxActive" value="10" />
<property name="maxIdle" value="10" />
<property name="maxWait" value="10000" />
<property name="minIdle" value="3" />
<property name="removeAbandoned" value="true" />
<property name="removeAbandonedTimeout" value="300" />
<property name="logAbandoned" value="false" />
<property name="accessToUnderlyingConnectionAllowed"
value="true" />
</bean>
<bean id="jdbcConnectionConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:jdbc-db.properties" />
</bean>
<bean id="sqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>WEB-INF/SqlMapConfig.xml</value>
</property>
<property name="useTransactionAwareDataSource">
<value>true</value>
</property>
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>
edit: here is the full stack trace
java.lang.OutOfMemoryError: Java heap space
at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:99)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:393)
at java.lang.StringBuffer.append(StringBuffer.java:225)
at org.apache.struts.taglib.html.OptionsCollectionTag.addOption(OptionsCollectionTag.java:313)
at org.apache.struts.taglib.html.OptionsCollectionTag.doStartTag(OptionsCollectionTag.java:266)
at org.apache.strutsel.taglib.html.ELOptionsCollectionTag.doStartTag(ELOptionsCollectionTag.java:220)
at org.apache.jsp.WEB_002dINF.jsp.humanRestAreagoiotion.humanRestAreagoiotionCreate_jsp._jspx_meth_html_005foptionsCollection_005f2(humanRestAreagoiotionCreate_jsp.java:1984)
at org.apache.jsp.WEB_002dINF.jsp.humanRestAreagoiotion.humanRestAreagoiotionCreate_jsp._jspx_meth_html_005fselect_005f2(humanRestAreagoiotionCreate_jsp.java:1948)
at org.apache.jsp.WEB_002dINF.jsp.humanRestAreagoiotion.humanRestAreagoiotionCreate_jsp._jspx_meth_html_005fform_005f0(humanRestAreagoiotionCreate_jsp.java:1578)
at org.apache.jsp.WEB_002dINF.jsp.humanRestAreagoiotion.humanRestAreagoiotionCreate_jsp._jspService(humanRestAreagoiotionCreate_jsp.java:457)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
at org.apache.jasper.servlet.JspServlet._serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1078)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:295)
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:396)
at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:347)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:232)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
Dec 28, 2016 4:46:40 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet action threw exception
java.lang.OutOfMemoryError: Java heap space
at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:99)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:393)
at java.lang.StringBuffer.append(StringBuffer.java:225)
at org.apache.struts.taglib.html.OptionsCollectionTag.addOption(OptionsCollectionTag.java:313)
at org.apache.struts.taglib.html.OptionsCollectionTag.doStartTag(OptionsCollectionTag.java:266)
at org.apache.strutsel.taglib.html.ELOptionsCollectionTag.doStartTag(ELOptionsCollectionTag.java:220)
at org.apache.jsp.WEB_002dINF.jsp.humanRestAreagoiotion.humanRestAreagoiotionCreate_jsp._jspx_meth_html_005foptionsCollection_005f2(humanRestAreagoiotionCreate_jsp.java:1984)
at org.apache.jsp.WEB_002dINF.jsp.humanRestAreagoiotion.humanRestAreagoiotionCreate_jsp._jspx_meth_html_005fselect_005f2(humanRestAreagoiotionCreate_jsp.java:1948)
at org.apache.jsp.WEB_002dINF.jsp.humanRestAreagoiotion.humanRestAreagoiotionCreate_jsp._jspx_meth_html_005fform_005f0(humanRestAreagoiotionCreate_jsp.java:1578)
at org.apache.jsp.WEB_002dINF.jsp.humanRestAreagoiotion.humanRestAreagoiotionCreate_jsp._jspService(humanRestAreagoiotionCreate_jsp.java:457)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
at org.apache.jasper.servlet.JspServlet._serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1078)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:295)
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:396)
at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:347)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:232)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
[SYS] [2016-12-28 16:46:40.651] DSC-ID[NULL_ID] SID[16CF384A6BBB483CD2CC7009350B5598] RID[654474] [ERROR] ID:861385 CODE:AI-90-0000 MESSAGE:[AI-90-0000]Unexpected exception occurred. Exception Type: javax.servlet.ServletException, Message: java.lang.OutOfMemoryError: Java heap space DATE & TIME:2016-12-28 16:46:40.408
com.globaldenso.ai.common.core.exception.SystemException: [AI-90-0000]Unexpected exception occurred. Exception Type: javax.servlet.ServletException, Message: java.lang.OutOfMemoryError: Java heap space
at org.apache.jsp.WEB_002dINF.jsp.common.error_jsp._jspService(error_jsp.java:237)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
at org.apache.jasper.servlet.JspServlet._serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:488)
at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:416)
at org.apache.catalina.core.StandardHostValve.throwable(StandardHostValve.java:270)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:595)
Caused by: javax.servlet.ServletException: java.lang.OutOfMemoryError: Java heap space
at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:865)
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:794)
at org.apache.jsp.WEB_002dINF.jsp.humanRestAreagoiotion.humanRestAreagoiotionCreate_jsp._jspService(humanRestAreagoiotionCreate_jsp.java:471)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
at org.apache.jasper.servlet.JspServlet._serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1078)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:295)
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:396)
at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:347)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:232)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.globaldenso.ai.tro2.core.filter.RequestLoggingFilter.doFilter(RequestLoggingFilter.java:89)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.globaldenso.ai.tro2.core.filter.LogContextFilter.doFilter(LogContextFilter.java:80)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.globaldenso.ai.tro2.core.filter.DensoContextFilter.doFilter(DensoContextFilter.java:94)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.globaldenso.na.nascs_admin.common.filter.PageAccessFilter.doFilter(PageAccessFilter.java:108)
at com.globaldenso.na.nascs_admin.common.filter.PageAccessFilter.doFilter(PageAccessFilter.java:90)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.globaldenso.na.nascs_admin.common.filter.ChgPwdFilter.doFilter(ChgPwdFilter.java:106)
at com.globaldenso.na.nascs_admin.common.filter.ChgPwdFilter.doFilter(ChgPwdFilter.java:81)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.globaldenso.na.nascs_admin.common.filter.LoginFilter.doFilter(LoginFilter.java:110)
at com.globaldenso.na.nascs_admin.common.filter.LoginFilter.doFilter(LoginFilter.java:83)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.globaldenso.ai.tro2.core.filter.CheckFilter.doFilter(CheckFilter.java:80)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.globaldenso.ai.tro2.core.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:92)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
... 7 more
Caused by: java.lang.OutOfMemoryError: Java heap space
at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:99)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:393)
at java.lang.StringBuffer.append(StringBuffer.java:225)
at org.apache.struts.taglib.html.OptionsCollectionTag.addOption(OptionsCollectionTag.java:313)
at org.apache.struts.taglib.html.OptionsCollectionTag.doStartTag(OptionsCollectionTag.java:266)
at org.apache.strutsel.taglib.html.ELOptionsCollectionTag.doStartTag(ELOptionsCollectionTag.java:220)
at org.apache.jsp.WEB_002dINF.jsp.humanRestAreagoiotion.humanRestAreagoiotionCreate_jsp._jspx_meth_html_005foptionsCollection_005f2(humanRestAreagoiotionCreate_jsp.java:1984)
at org.apache.jsp.WEB_002dINF.jsp.humanRestAreagoiotion.humanRestAreagoiotionCreate_jsp._jspx_meth_html_005fselect_005f2(humanRestAreagoiotionCreate_jsp.java:1948)
at org.apache.jsp.WEB_002dINF.jsp.humanRestAreagoiotion.humanRestAreagoiotionCreate_jsp._jspx_meth_html_005fform_005f0(humanRestAreagoiotionCreate_jsp.java:1578)
at org.apache.jsp.WEB_002dINF.jsp.humanRestAreagoiotion.humanRestAreagoiotionCreate_jsp._jspService(humanRestAreagoiotionCreate_jsp.java:457)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
at org.apache.jasper.servlet.JspServlet._serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1078)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:295)
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:396)
at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:347)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:232)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
eclipse.ini defines memory for eclipse itself. You have to define -Xmx2048 into your application's launcher. If you launch your webapp using eclipse try to follow this link :
http://crunchify.com/how-to-increase-tomcat-heapsize-jvm-heap-in-eclipse-ede/
Please note that you'll have to change in tomcat itself if you launch it outside of eclipse :
http://crunchify.com/how-to-change-jvm-heap-setting-xms-xmx-of-tomcat/