Out of memory exception from a JSP File..
Description:
Getting out of memory exception while exporting a CSV file frmom JSP
While clicking the download button, it forwards to a struts action
class and from there it calls PO and DAO for database calls and
executing the query to download the data...
and the data is put in a List..and finally a JSP is converting the List
object to one StringBuffer object and writes it to an CSV file.
Expected Solutions:
1. I need to keep the session active until it gets downloaded..bcos it
takes time to download the file, mean -while the session get destroyed
2. Performance tuning to Fix that error
Please help me out at the earliest...
Thanks in advance..!
> Please help me out at the earliest...
How much money is my urgent assistance worth to you?
[ It might be better to be *patient* and wait for
the free answers. ]
On 19 Oct 2005 03:16:40 -0700, praveenkumarr@gmail.com wrote or quoted
>Getting out of memory exception while exporting a CSV file frmom JSP
If alternate code to write CSV files would help you, see
http://mindprod.com/jgloss/csv.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
> Out of memory exception from a JSP File..
>
[quoted text clipped - 6 lines]
> and the data is put in a List..and finally a JSP is converting the List
> object to one StringBuffer object and writes it to an CSV file.
How large is this resulting StringBuffer ?
You're better to progressively produce the result in chunks than store the
complete result in memory.
> Expected Solutions:
> 1. I need to keep the session active until it gets downloaded..bcos it
> takes time to download the file, mean -while the session get destroyed
You're kidding ?!? How long is the session timeout (it's usually 30 minutes
by default) ? How long does it take to produce the CSV ?
Web is request/reply and must be fast. It's not for running long operations.
> 2. Performance tuning to Fix that error
>
> Please help me out at the earliest...
If your description is accurate, you are in too deep trouble for getting a
working solution without a review of the design. You better hire someone to
do the job.
> Thanks in advance..!
Roedy Green - 20 Oct 2005 01:48 GMT
>How large is this resulting StringBuffer ?
>You're better to progressively produce the result in chunks than store the
>complete result in memory.
This is the way CSVWriter works. It squirts output a field at a time
to a BuffereOutputWriter.
If the CSV writing is not too deeply buried in somebody else's code
swapping the CSV writer may be your fastest way to solving. it.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
praveenkumarr@gmail.com - 20 Oct 2005 09:22 GMT
Thanks for ur reply..!
The size of the dowloading may differ from 1MB- 5MB..
Reg. Session Timeout i have put session.setMaxInactiveInterval(-1) in
the Action Action Class, but still its not working i believe...
The download may take around 45mins sometimes and am getting the "Page
Cannot be displayed" after that particular period of time...
Kindly help me please......
Ben_ - 20 Oct 2005 17:18 GMT
Try Roedy's component or change the way you produce the CSV to not build it
with a SingleString. It comes as no surprise to me that a MB large string
wouldn't fit in memory...
Roedy Green - 22 Oct 2005 02:13 GMT
>Try Roedy's component or change the way you produce the CSV to not build it
>with a SingleString. It comes as no surprise to me that a MB large string
>wouldn't fit in memory...
You could be in a thrashing situation shuffling objects around like
mad to make room for an ever-growing StringBuilder. As a quick fix,
construct the StringBuilder (not StringBuffer) the right size to
start. Also consider reusing it with setLength(0) if you are using it
more or less continuously.
If you don't know, put some effort into making a reasonable estimate
based on past history and what you know about the coming case.
Also consider serialising the creating of CSV files so you don't try
to construct 20 of them at once.
See http://mindprod.com/jgloss/queue.html
However I think you will find doing it with my CSVWriter will solve
your problem without any fanatic tweaking.
see http://mindprod.com/jgloss/csv.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
praveenkumarr@gmail.com - 22 Oct 2005 10:00 GMT
Thanks Roedy, Thanks for ur reply and suggestion, will try building
thru StringBuilder Class..