0

When i export content in doc format then i get java heap space error,

java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOf(Unknown Source)
    at java.io.ByteArrayOutputStream.write(Unknown Source)
    at sun.nio.cs.StreamEncoder.writeBytes(Unknown Source)
    at sun.nio.cs.StreamEncoder.implWrite(Unknown Source)
    at sun.nio.cs.StreamEncoder.write(Unknown Source)
    at sun.nio.cs.StreamEncoder.write(Unknown Source)
    at java.io.OutputStreamWriter.write(Unknown Source)
    at java.io.Writer.write(Unknown Source)
2
  • Can you try to make the format of your question more readable, and possibly be a little more clear about what your question is? Commented Oct 19, 2009 at 5:38
  • my question is:i get java heap space error(OutOfMemoryError) when i try to export a huge content in doc format in jasper reports Commented Oct 19, 2009 at 5:56

8 Answers 8

6

Best add a

-XX:+HeapDumpOnOutOfMemoryError

to create heapdump whenever an OutOfMemoryError occurrs, and then analyse the heap dump with e.g. Eclipse Memory Analyzer which will show you the amount of objects and usually clearly identifies the objects causing the OutOfMemory Error.

Sign up to request clarification or add additional context in comments.

Comments

4
java.lang.OutOfMemoryError: Java heap space

Java is simply running out of memory. It cannot allocate more memory anymore. The remnant of the stacktrace is irrelevant, it just happen to happen exactly during the array copy action. It could have happened anywhere.

Apparently you're trying to generate a report based on an extremely large dataset (thousands or tenthousands of records maybe), or you've supplied JVM too little memory. You should then just ensure that JVM has enough memory to handle all that data. The default is 128MB or 256MB, depending on JVM and environment used. Start to double that amount using the -Xmx argument for the JVM.

E.g.

java -Xmx512M (other arguments here)

You may also want to profile your application to check how many memory it is actually using and then optimize the argument for that.

On the other hand, if you're processing really a lot of data, then consider doing it in parts, e.g. first the first thousand records and then the second thousand records, etcetera.

Comments

1

Try increasing the memory that the JVM Starts with, and can use as its MAX.

Add these arguments to the launching of your program

-Xms500M

Replace the 500 with however many megs you want the JVM to start with.

-Xmx500M

Replace the 500 with however many megs you want the maximum memory the JVM can use to be.

3 Comments

i added the same thing in the control panel->java setting and restarted my machine, it dint work. i added a space before it, should there be a space in the beginning
There should be no space between -Xmx and 500M. There should be spaces between the various options (before the - sign). So the command would look like java -Xms500M -Xmx500M ...
-Xms rarely that useful unless you want to pre-virtually-allocate, stick to -Xmx alone allows for the OS to allocate as necessary.
1

If you dataset is huge, then you need to page the report generation itself. I was doing some research large dataset for jasper reports and found this article quite informative.

Comments

1

You should go with Virtualizers feature of jasper reports. See an article here.

Comments

0

Is not needed a great amount of memory for usual reports. Is your document so big?

Maybe Jasper Reports goes in an infinite loop. Modify log4j level in order to get more clues about what's occurring. Try to delete some parts to know where it gets stuck.

I've used Jasper Reports and get some errors like this. Sometimes Jasper Reports behaviour is, well, strange.

Good luck.

Comments

0

You can change memory params in setenv.bat file. below is the path for the same.

jasperhome/apache-tomcat/bin/setenv.bat

here you can change JvmMs and JvmMx parameters as per your requirement. Once change the param you need to restart the jasper server. one way to do this is by restart jasper services by task manager.

Comments

0

If you have following error in Jasper iReport:

Error filling print... java.lang.OutOfMemoryError: Java heap space null java.lang.OutOfMemoryError: Java heap space  Print was not filled. Try using an EmptyDataSource...

To solve the error do the following:

  1. Increase Java memory space in your computer

    1. Go to Control Panel.

    2. Go to Programs.

    3. Go to Java.

    4. Go to Java General tab to Java tab.

    5. Click View.

    6. After that set as in the below screenshot.

      enter image description here

  2. Go to the iReport and make the following changes.

    enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.