4

I am developing a plagiarism detection application, which involves lot of document processing. For indexing the documents I am using Apache Lucene and I am using Apache solr as a document server. I am using Jasper reporting as a reporting module. After processing all the documents and detecting plagiarism I am calling an interface developed using Jasper reporting and at that time java heap space exception is occurred. I tried to increase heap space in the application but the same exception is still thrown out. Is there any suggestion to help me solve this problem.

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2760)
at java.util.Arrays.copyOf(Arrays.java:2734)
at java.util.ArrayList.ensureCapacity(ArrayList.java:167)
at java.util.ArrayList.add(ArrayList.java:351)
at reportingModule.PeerSearchUI.generateResults(PeerSearchUI.java:901)
at reportingModule.PeerSearchUI.setResultDetails(PeerSearchUI.java:833)
at gui.form.WizardForm.ViewButtonActionPerformed(WizardForm.java:1372)
at gui.form.WizardForm.access$1200(WizardForm.java:50)
at gui.form.WizardForm$13.actionPerformed(WizardForm.java:870)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6038)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
at java.awt.Component.processEvent(Component.java:5803)
at java.awt.Container.processEvent(Container.java:2058)
at java.awt.Component.dispatchEventImpl(Component.java:4410)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
at java.awt.Container.dispatchEventImpl(Container.java:2102)
at java.awt.Window.dispatchEventImpl(Window.java:2429)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
10
  • Did the error occur in the same place both before and after increasing the heap space? Commented Aug 22, 2011 at 16:36
  • Trim the amount of memory you use? I'm not sure what else to say given the information. Could we have more details as to how your code works? Could we actually have some code? Commented Aug 22, 2011 at 16:38
  • @Grimace: Thanks for the reply. Ya, it occurred in the same place. My laptop has a 2GB memory but while the application is run it is using only about 800mb including every other application. Commented Aug 22, 2011 at 16:38
  • 1
    Increase that value! Try 1536M for instance. 512 may be a very low value. Commented Aug 22, 2011 at 16:55
  • 1
    What version of java are you running? java -version Commented Aug 22, 2011 at 18:10

2 Answers 2

7

From your exception, the error is related to heap (not permgen or any other specific spaces) so the only parameter to tune will be -Xmx and so here are my suggestions :

Have the JVM to use more memory using the -Xmx - try 1G : -Xmx1024m

If that ends up throwing the same error,

  • Start JVM with argument -XX:+HeapDumpOnOutOfMemoryError this will give you a heap dump when program goes in to OOM.
  • Use a tool like visualVM to analyze the heap dump obtained. That will help in identifying memory leaks.

Other than this, there is no generic solution to fix java.lang.OutOfMemoryError: Java heap space - It can be very much application specific.

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

Comments

3

It would help if you would tell us what the variable types you are using to store the document index and reported results.

Try running the reporting app in a separate JVM from the document indexing process.

Indexing documents is a resource intensive operation and if it is holding all the memory used during indexing and then you try to query the index for your report, it can consume even more.

Let's look at the stack trace from the top. The first three lines (read in reverse order) show the smoking gun.

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space at     
java.util.Arrays.copyOf(Arrays.java:2760) at java.util.Arrays.copyOf(Arrays.java:2734) at 
java.util.ArrayList.ensureCapacity(ArrayList.java:167) at java.util.ArrayList.add(ArrayList.java:351) at 

The JVM

  1. checked the size of an array to see if it was big enough
  2. attempts to copy an array (which is the default behavior when growing a Vector)
  3. exhausts available memory and throws the OutOfMemoryError exception

The stack trace doesn't mention the exact array but it has to be a large one.

Question: How are you storing the completed index and where are you putting the report results? Since you haven't said what structure, I'll assume for now a Vector which, is convienent to use when you don't know how much data you have, but is also very wasteful when its capacity is increased. If not told otherwise, it will double in size each time it needs more room so a initial size of 100 bytes quickly can turn into tens of megabytes which almost half of the new room empty.

The next two lines are from your reporting code. I would assume that the reporting module part of the UI has a reference to the array/vector/list being filled with data. Tell us what type it is.

reportingModule.PeerSearchUI.generateResults(PeerSearchUI.java:901) at  
reportingModule.PeerSearchUI.setResultDetails(PeerSearchUI.java:833) at 

The line below implies the exception happens after you've clicked a button, 'View Results' possibly, which kicks off a report.

gui.form.WizardForm.ViewButtonActionPerformed(WizardForm.java:1372) at 

This implies that the results are available and are waiting to be displayed. If that is true, then you need to have a better way to isolate the results.

How about showing only 1 page of results at a time. Only show the first 10 rows, then show the next 10, etc.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.