-1

我是一个新的软件开发人员,真的需要一些帮助。我的任务是使用 FOP 从数据库中的数据生成 PDF。我编写了该程序并且它可以工作,但并非在所有情况下都可以。只要我检索的数据行数相当小,一切都可以正常工作——最多不到 10000 行。当我尝试为大于 10000 行的数据集生成报告时,出现内存不足错误(Java 堆空间)。

从数据库读取的代码:

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));
}

我将程序的内存增加到 2GB,但仍然出现错误。解决此问题的任何帮助将不胜感激。

4

1 回答 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.

于 2012-05-02T09:41:54.437 回答