You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Renjith R <ra...@gmail.com> on 2014/06/04 12:02:32 UTC

OutofMemory error on using SXSSF

I am using SXSSF to write 1 Million(worst case scenario) records.

Following is the way i have coded it.
I have to write the records to an already existing excel template. This
template is
available in the class path. I will copy this template to a common
location. Load this file using XSSFWorkBook.
SXSSFWorkbook is initialized with XSSFWorkBook and window size(-1) as
parameter.

when ever the record count reaches multiple of 100, i will  flush the sheet.

Pseudo Code:
if(count % 100 == 0){
    ((SXSSFSheet)sheet).flush(100); //keeps only 100 rows in memory
}

But while executing this, heap memory is gradually increasing and it ends
up in Outofmemory exception. Maximum heap memory size of my machine is
about 1.5 GB.

Is it an expected behaviour? ie. is it expected to go beyond 1.5 GB while
writing record of size ~ 1 Million?

-- 
*RENJITH R*
9446011990

Re: OutofMemory error on using SXSSF

Posted by Renjith R <ra...@gmail.com>.
This is resolved now :). It has nothing to do with SXSSFWorkbook. One
particular column in the report (Represents error in report) needs to be
RED in color. So I applied Style to that column. Instead of creating the
Style outside the FOR loop and applying it for all cells that comes under
the column, i was creating a style each time i write error. Out of 1
million records, if 1/2 a million are having errors my code was generating
1/2 a million CellStyles. That was eating my heap memory.

Following link helped me to resolve it.
http://poi.apache.org/faq.html#faq-N100EF


On Wed, Jun 4, 2014 at 3:32 PM, Renjith R <ra...@gmail.com> wrote:

> I am using SXSSF to write 1 Million(worst case scenario) records.
>
> Following is the way i have coded it.
> I have to write the records to an already existing excel template. This
> template is
> available in the class path. I will copy this template to a common
> location. Load this file using XSSFWorkBook.
> SXSSFWorkbook is initialized with XSSFWorkBook and window size(-1) as
> parameter.
>
> when ever the record count reaches multiple of 100, i will  flush the
> sheet.
>
> Pseudo Code:
> if(count % 100 == 0){
>     ((SXSSFSheet)sheet).flush(100); //keeps only 100 rows in memory
> }
>
> But while executing this, heap memory is gradually increasing and it ends
> up in Outofmemory exception. Maximum heap memory size of my machine is
> about 1.5 GB.
>
> Is it an expected behaviour? ie. is it expected to go beyond 1.5 GB while
> writing record of size ~ 1 Million?
>
> --
> *RENJITH R*
> 9446011990
>



-- 
*RENJITH R*
9446011990