File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Heap Space Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Heap Space Error" Watch "Heap Space Error" New topic
Author

Heap Space Error

Neeba Rebbaca
Ranch Hand

Joined: Oct 21, 2008
Posts: 157
i'm launching applet from jsp. For some data its working fine. when the data are really too big,its throwing Java heap space error. I increased the JVM to -Xmx512m
in Java Runtime Environment Settings.

But still getting the same error. If i run from html i'm not getting the error. Only when i launch it from Jsp i'm getting this error. I'm using Tomcat 5.5
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Where is the exception happening, on the server (JSP Tomcat side) or in the browser (Applet sandbox).

Can you post the relevant part of the stacktrace?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Neeba Rebbaca
Ranch Hand

Joined: Oct 21, 2008
Posts: 157
Getting browser.


Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Java heap space
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:433)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)


root cause

javax.servlet.ServletException: Java heap space
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774)
org.apache.jsp.index_jsp._jspService(index_jsp.java:118)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)


root cause

java.lang.OutOfMemoryError: Java heap space


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.27 logs.

Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

OK, you're seeing the error in the browser but the OOME is happening on the server within Tomcat.

Without seeing your code it will be impossible to tell what's causing this.
Probably 90% of the times that I've seen an OOME like this, it's due to something causing an infinite recursive loop.

Can you post the code to the JSP that you're hitting when this happens?

Vinoth Thirunavukarasu
Ranch Hand

Joined: Dec 18, 2008
Posts: 164

You can increase heap size for Tomcat.


Java Best Practices
Linux Best Practices
Amortization Calculator

Neeba Rebbaca
Ranch Hand

Joined: Oct 21, 2008
Posts: 157
i believe it can't be due to infinite loop. because i getting this error in a place where i tried to reterive data from a database.From database i will get a xml. the xml is really a huge on.

Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Vinoth Thirunavukarasu wrote:You can increase heap size for Tomcat.


It's always a good idea to read all the post in a thread before suggesting a solution.
In this case, you'll notice that the original poster already mentioned increasing heap size in his first post.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Just how big is this XML String?

If it's big enough that one call uses up all the ram you have in a JVM with 512m allotted, then it's probably more than what you want to be loading into a JSP to pass to an applet. You might find that increasing the heap space further will stop the problem in Tomcat but I suspect that you're going to run into issues either with the network or in the client.

Have you considered restructuring your app to first load the applet and then have the applet make calls to the server to get chunks of XML data as it needs it, instead of trying to pass the whole thing to your applet right up front?
Neeba Rebbaca
Ranch Hand

Joined: Oct 21, 2008
Posts: 157
should i have to increase m/y space for tomcat seperately? I have just set the memory space in control Panel --->java ---->java ---->runtime settings.

have to set for Tomcat seperately?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you have the Tomcat manager app installed log into it and go to the Server Status page.
It will show you how much ram is allocated to Tomcat's JVM.

How to increase the heap space for Tomcat depends on which OS you're using and how you've installed Tomcat.
Vinoth Thirunavukarasu
Ranch Hand

Joined: Dec 18, 2008
Posts: 164




Just add
export JAVA_OPTS="-Xmx128000000 " in catalina.sh or .bat file In this way I had done.
We have already discussed about this webpage


@Ben Souther
I made that solution He haven't increased heap size for tomcat.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Vinoth Thirunavukarasu wrote:Just add
export JAVA_OPTS="-Xmx128000000 " in catalina.sh or .bat file


Again, how you do this depends on how you've installed Tomcat.
If it's been installed as a Windows service, your instructions won't work because the catalina wrapper files never get run.
Vinoth Thirunavukarasu
Ranch Hand

Joined: Dec 18, 2008
Posts: 164

Yes you are right.
Thanks for notifying me.
Amol Nayak
Ranch Hand

Joined: Oct 26, 2006
Posts: 218
First it is a good idea to move this piece of code out from JSP to a Java class. It may not help you with the OutOfMemoryError but it is a good practice..

What is the size of the xml you store in your database column?

Usually BLOB datatype is used for storing such huge amount of Data. Instead of loading the entire data into a String i would suggest you to get an InputStream for this BLOB and use SAX parser to parse it.
I am sure not all details in the file needs to be passed to the client

Not sure if increasing the Heap size would help to a great extent, more the number of users more the memory usage and more the chances of OOME, you need to redesign somewhere.

If you can give some details of what you are trying to achieve maybe somebody can throw some light on it.
Srinivasan Elangovan
Greenhorn

Joined: Apr 11, 2012
Posts: 3

To avoid this issue.I simply stop writing the data's into excel instead of that i write data's into streams and retrieved from that. here the code snippet.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Heap Space Error