title: javax.servlet.ServletException: java.lang.OutOfMemoryError: Java heap space
body: <p>I want to extract nouns from selected text on my webpage, and highlight them when the text is displayed.So I use OpenNLP library for parsing and getting the list of nouns. It runs well in java class without memory problem though it took 6-7 seconds before showing the output, but when I run the code in jsp page, I got these error:</p>
  
  <pre><code>    javax.servlet.ServletException: java.lang.OutOfMemoryError: Java heap space
      org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:909)
      org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:838)
      org.apache.jsp.highlightText_jsp._jspService(highlightText_jsp.java:294)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  </code></pre>
  
  <p>root cause</p>
  
  <pre><code>java.lang.OutOfMemoryError: Java heap space
      opennlp.model.AbstractModelReader.getParameters(AbstractModelReader.java:144)
      opennlp.maxent.io.GISModelReader.constructModel(GISModelReader.java:75)
      opennlp.model.GenericModelReader.constructModel(GenericModelReader.java:59)
      opennlp.model.AbstractModelReader.getModel(AbstractModelReader.java:87)
      opennlp.tools.util.model.GenericModelSerializer.create(GenericModelSerializer.java:35)
      opennlp.tools.util.model.GenericModelSerializer.create(GenericModelSerializer.java:31)
      opennlp.tools.util.model.BaseModel.loadModel(BaseModel.java:231)
      opennlp.tools.util.model.BaseModel.&lt;init&gt;(BaseModel.java:181)
      opennlp.tools.postag.POSModel.&lt;init&gt;(POSModel.java:82)
      opennlp.tools.parser.ParserModel$POSModelSerializer.create(ParserModel.java:49)
      opennlp.tools.parser.ParserModel$POSModelSerializer.create(ParserModel.java:45)
      opennlp.tools.util.model.BaseModel.finishLoadingArtifacts(BaseModel.java:303)
      opennlp.tools.util.model.BaseModel.loadModel(BaseModel.java:240)
      opennlp.tools.util.model.BaseModel.&lt;init&gt;(BaseModel.java:181)
      opennlp.tools.parser.ParserModel.&lt;init&gt;(ParserModel.java:152)
      model.parser.parserAction(parser.java:59)
      org.apache.jsp.highlightText_jsp._jspService(highlightText_jsp.java:143)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  </code></pre>
  
  <p>Some solutions I read suggest to increase heap memory size of apache tomcat by doing this:</p>
  
  <pre><code>set CATALINA_OPTS=-Xms256m -Xmx512m
  </code></pre>
  
  <p>so I set it to -Xmx2g, but it gives the same error still. I dont think I need to modify JVM heap size,(Right click project in Netbeans > Properties > Run > VM Options > set -Xmx) but did try it though and it wasn't successfull.</p>
  
  <p>Never had this error before, so I have no idea what should I do. Appreciate any help, thanks.</p>