-1

I am a new software developer and really need some help. I have been given the task to generate a PDF from data in the database, using FOP. I wrote the program and it works, but not in all situations. Everything works as long as the number of rows of data I retrieve are fairly small - up to just under 10000 rows. When I try to generate a report for datasets larger than 10000 rows I get an out of memory error (Java heap space).

The code that reads from the database:

while (rs.next()) {
   EMP_ID = rs.getString("EMP_ID");
   EMP_NAME = rs.getString("EMP_NAME");
   EMP_SALARY = rs.getString("EMP_SALARY");
   EMP_PROJECT = rs.getString("EMP_PROJECT");
   EMP_POSITION = rs.getString("EMP_POSITION");
   team.addMember(d.DataGetSet(EMP_ID, EMP_NAME, EMP_SALARY, EMP_PROJECT,
         EMP_POSITION));
}

I increased the memory for the program to 2GB, but still the error occurs. Any help in getting around this problem would be appreciated.

8
  • 1
    It's hard to diagnose what might be wrong with your program without seeing some code. Please add relevant portions to your question.
    – Perception
    Apr 29, 2012 at 5:15
  • while (rs.next()) { EMP_ID = rs.getString("EMP_ID"); EMP_NAME = rs.getString("EMP_NAME"); EMP_SALARY = rs.getString("EMP_SALARY"); EMP_PROJECT = rs.getString("EMP_PROJECT"); EMP_POSITION = rs.getString("EMP_POSITION"); team.addMember(d.DataGetSet(EMP_ID, EMP_NAME, EMP_SALARY, EMP_PROJECT, EMP_POSITION)); }
    – sai
    Apr 29, 2012 at 5:21
  • tats the loop i use to retrieve data and pass it to a getter and setter method,also add it to a Arraylist named member so i can use it write to xml or fo file
    – sai
    Apr 29, 2012 at 5:22
  • I believe your team.addMember() is creating some sort of in-memory collection that is simply getting populated. Although 10k looks like a small number, this could be a problem. Apr 29, 2012 at 5:45
  • ok,then how do i move all my data into an array so that i can use it for next step in creating xml or fo file.....
    – sai
    Apr 29, 2012 at 5:47

1 Answer 1

1

If you are running out of memory and you don't know where to start, I suggest a divide-and-conquer approach to steer you to the right area. For example, comment out the code that creates the PDF then test again. Does it run out of memory? If so, comment out the part adding to the array (but keep the call to d.DataGetSet) and test again. This will hopefully let you know where to attack without having to learn how to profile Java memory (which has it's own learning curve).

If you still aren't getting anywhere, try using JVisualVM (part of the JDK). Connect it to your application as it is running and do a "heap dump". This might help you spot what's hanging on to so much memory.

Finally - are you sure you upped the memory and that took effect? Just a double-check.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.