-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.

Perception
  • 79,279
  • 19
  • 185
  • 195
sai
  • 1
  • 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 '12 at 05: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 '12 at 05: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 '12 at 05: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. – Kalpak Gadre Apr 29 '12 at 05: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 '12 at 05:47
  • It looks like your most recent [question](http://stackoverflow.com/questions/10371176/program-to-retrive-data-from-db-and-write-in-pdf-using-fop-jar) was exactly the same question as this only with less detail. If you don't get an answer to your question asking it again, with *less* detail than a question you were already told didn't look very clear *isn't* the way to go. – Flexo Apr 29 '12 at 09:57
  • What does the d.DataGetSet do (and create)? Would it be possible to generate pdf on the fly so you don't need all data in memory at once? – Roger Lindsjö Apr 29 '12 at 12:41
  • @Roger DataGetSet is just a getter and setter class.And about retriving in fly,actually im not well versed in FOP.i got a sample program to write in PDF with static input.I got that sample program when i download FOP 1.0 jar from apache.I just changed bit of things and class name and also inserted the code to retrieve data from DB. – sai Apr 29 '12 at 13:02

1 Answers1

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.

Paul Jowett
  • 6,513
  • 2
  • 24
  • 19