I need to create a customized xls report from DB data, after putting all the data in string buffer and ran the application, i am getting below exception:
JVMST109: Insufficient space in Javaheap to satisfy allocation request
Exception in thread "main" java.lang.OutOfMemoryError at java.lang.StringBuffer.append(StringBuffer.java(Compiled Code))
at org.apache.log4j.helpers.PatternConverter.format(PatternConverter.java:79)
at org.apache.log4j.PatternLayout.format(PatternLayout.java:495)
............ etc
Can you please help me with this. Actually Data size is about 9MB (9234KB).
I really dont think storing all the data for a report within a StringBuffer is the most optimal way.
They way I do it is parse a result set into a LinkedList of objects that each represent a single row. This allows you to retrieve the desired information as well as perform calculations etc.
StringBuffers have a capacity, expressed as an int, which represents the number of characters in the buffer. So the max capacity should be Integer.MAX_VALUE (or 2 ^31 -1) . Each character will be a 16-bit unicode character, so 2 bytes per character will require a heap size of (2 ^31 -1) * 2 bytes which is about a 4 GB heap (excluding any other object in the heap).
Paul Sturrock wrote:StringBuffers have a capacity, expressed as an int, which represents the number of characters in the buffer. So the max capacity should be Integer.MAX_VALUE (or 2 ^31 -1) . Each character will be a 16-bit unicode character, so 2 bytes per character will require a heap size of (2 ^31 -1) * 2 bytes which is about a 4 GB heap (excluding any other object in the heap).
You mean to say a stringbuffer can hold upto 4GB of data? i am using java 1.4.2;
Nagaraj Shivaklara
Ranch Hand
Joined: Dec 16, 2008
Posts: 72
posted
0
Joshua Barrett wrote:Hello Nagaraj
What API are you using to create the .xls report?
I really dont think storing all the data for a report within a StringBuffer is the most optimal way.
They way I do it is parse a result set into a LinkedList of objects that each represent a single row. This allows you to retrieve the desired information as well as perform calculations etc.
Hope this helps
Hi,
I am using POI 1.1 ...
Actually i am using java 1.4.2 and the structure of excel is like it has 4 tabs and each tab contains different data. What i have done is created 4 stringbufferes and adding all the buffer objeccts to single buffer as xml type and then converting xml to xls..
Nagaraj Shivaklara wrote:You mean to say a stringbuffer can hold upto 4GB of data? i am using java 1.4.2;
There is no such thing as a 'stringBuffer' - unless it's a class YOU created. The class provided is called 'StringBuffer' - is that what you are referring to?
Never ascribe to malice that which can be adequately explained by stupidity.
Nagaraj Shivaklara
Ranch Hand
Joined: Dec 16, 2008
Posts: 72
posted
0
fred rosenberger wrote:
Nagaraj Shivaklara wrote:You mean to say a stringbuffer can hold upto 4GB of data? i am using java 1.4.2;
There is no such thing as a 'stringBuffer' - unless it's a class YOU created. The class provided is called 'StringBuffer' - is that what you are referring to?
In almost every case, when I see someone worrying about the maximum size of a StringBuffer (or array or List etc etc etc) because they are trying to hold the whole of a file in memory I know that they have a design problem. I could be wrong but this certainly looks to be the case here.
In the OP's boots I would re-factor the design so that very little needed to be held in memory at a time. This normally means having sequential data creation and sequential writing of this data.
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.