简体   繁体   中英

Buffer is to small

In my web app I am using BufferedWriter so the user will be able to generate and download reports.

File evl = new File(tmpDirPath + "evl.xml");
portEVL.deleteOnExit();
fw = new FileWriter(evl);
bw = new BufferedWriter(fw);
bw.write(getHeader().concat(evlBuffer.toString()));

When writing to the buffer I get the following error message :

Caused By: java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2882)
at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:100)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:390)
at java.lang.StringBuilder.append(StringBuilder.java:119)

I try to increase the buffer size but still the same error

Is there a why to separate the writing process or perhaps some other idea?

Your problem has nothing to do with the buffer space, you are running out of Heap space in your JVM!

Try increasing the heap size with these flags:

-Xms<size>        set initial Java heap size
-Xmx<size>        set maximum Java heap size
-Xss<size>        set java thread stack size

java -Xms16m -Xmx64m ClassName

The most important one for you is -Xmx<size> set maximum Java heap size

You can also always do it in gigabytes by putting java -Xmx2g ClassName

Here is the official Oracle documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM