views:

136

answers:

4

I get a java.lang.outOfMemoryError exception, while writing a big file to the servletOutputStream. Every response is by default wrapped using a ehcache.constructs.web.filter Object for GZIP compression. And as per the logs, the exception is thrown in the Filter object. Is there a way to increase the available memory so, that the outOfMemoryError Exception does not occur ?

A: 

Use -Xmx Java command line option as shown below

java -Xms256m -Xmx512m com.test.MyMain

Xms represents lower end of memory allocation and Xmx represents the upper end of memory allocation

navr
A: 

Set the following JVM options to your servlet container -Xmx256m -Xms128m (in Tomcat it is in catalina.sh / catalina.bat)

Bozho
A: 

You need to add the option "-Xmx1024m" to the java command which runs your servlet container. (Replace 1024m with whatever heap size you like; this means 1024 megabytes.) If you're using, say, Tomcat, then this means you set this in the environment variable CATALINA_OPTS. Your server configuration will vary.

However, the problem is buffering such a big file in memory. This is wasteful. Try this compression filter, which doesn't buffer this way:

http://sourceforge.net/projects/pjl-comp-filter/

Sean Owen
The file is 17MB large. Should it cause a problem?I am using a JBOSS server.
The Machine
I could imagine that taking 50+MB of heap with all the intermediate data structures. And, if your heap is left at the default of about 64MB, yes, it's a problem.While you can make the heap bigger, I really think it's better to use a filter that does not have to load the file into memory. This should not be necessary, and the filter above does not do it this way.
Sean Owen
A: 

Don't forget about possibly needing to increase your PermGen size:

-XX:PermSize=64m -XX:MaxPermSize=256m

Also do make sure you are efficiently streaming out the file. There may be unnecessarily large buffering in the output or inputstream pipe.

Pat
There are about 24k (pretty wide) rows returned by the database, which i am writing out to the servLet Output stream. Hence, there is a gargantuan amount of data stored in the memory. Do you know of a way to improve this. I need all the data fetched to be sent to the webClient, in a single response . Hence i dont think i can get out bathes of data from the Database.
The Machine