xmlbeans out of memory error.

Hello,

        I need to genrate a large XML file. I am using xmlbeans for genration. It works fine when i have to genrate a small file of upto 10,000 records but for my use I need as many as over 50,000 records for which I am getting this out of memory error.
                 
                The way I am doing it is  I keep genrating xml file in a while loop as long as I am haivng records in resultSet when there is no more data in result set after the while loop i write it to file using save(outputstream) (XMLTokenSource) .

 I am hoping if there is a way where i can keep writing to a file as I am adding new elements to the XML there by it does not have to build the tree in the memory and write all at once at the end.

Sunitha

sunithasAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MogalManicCommented:
Could you send a code sample?

It could be a garbage collection issue.
0
sunithasAuthor Commented:
only thing is result set may return as many as 200,000 records

private int genrateXML(ResultSet rs, OutputStream os, String office_code,
                  String userID, int cia_id) {
            int counter = 0;
            try {

                  ReportDocument rd = ReportDocument.Factory.newInstance();
                  rd.addNewReport();
                  ReportDocument.Report report = rd.getReport();
                  report.setCiaID(cia_id);
                  report.setUserID(userID);
                  report.setGenerationTime(Calendar.getInstance());

                  while (rs.next()) {
                        ReportDocument.Report.ReferralActivity referalActivity = report
                        .addNewReferralActivity();
                        counter++;
                        if(counter >3)
                              break;
                  
                        referalActivity.setLastName(rs.getString("last_name"));
                        referalActivity.setState(rs.getString("State"));
                        referalActivity.setPostalCode(rs.getString("zip_code"));
                        referalActivity.setSocialSecurityNumber(rs.getString("ssn"));
                        referalActivity.setAccountNumber(rs
                                    .getString("DISP_CNSUMR_ACCT_NUM"));
                        if (rs.getDate("date_processed") != null)
                              referalActivity.setDateSent(rs.getDate("date_processed")
                                          .toString());
                        else
                              referalActivity.setDateSent("");
                        String temp;
                        if (rs.getString("status").equals("2"))
                              referalActivity.setPickedYN("Y");
                        else if (rs.getString("status").equals("1"))
                              referalActivity.setPickedYN("N");
                        
                        System.out.println(referalActivity.toString());
                  }
                  rd.save(os);
                  

            } catch (IOException e1) {

                  e1.printStackTrace();

            } catch (SQLException e) {

                  e.printStackTrace();
            }
            return counter;
      }
0
MogalManicCommented:
Try splitting the function into two parts
  1) Process Result set
  2) Save results to OutputStream

This will allow the garbage collector to clean up the result set before saving the results to the stream.  Currently there are three objects in the memory that are competing for space
 1) The Result set
 2) The bean
 3) The outputStream

Something like this:
      private int genrateXML(ResultSet rs, OutputStream os, String office_code,
                           String userID, int cia_id)
               {
        int[] counter = {0};
         try {
            ReportDocument rd=getReportDocument(rs, office_code, userID, cia_id, counter);
            rs.close();
            rd.save(os);
                 } catch (IOException e1) {
                    e1.printStackTrace();
                 } catch (SQLException e) {
                    e.printStackTrace();
                 }
                 return counter[0];
             }

      private ReportDocument getReportDocument(ResultSet rs, String office_code,String userID, int cia_id, int[] counter)
            throws SQLException
      {
            ReportDocument rd = ReportDocument.Factory.newInstance();
            rd.addNewReport();
            ReportDocument.Report report = rd.getReport();
            report.setCiaID(cia_id);
            report.setUserID(userID);
            report.setGenerationTime(Calendar.getInstance());

            while (rs.next()) {
                   ReportDocument.Report.ReferralActivity referalActivity = report
                   .addNewReferralActivity();
                   counter[0]++;
                   if(counter[0] >3)
                          break;
               
                   referalActivity.setLastName(rs.getString("last_name"));
                   referalActivity.setState(rs.getString("State"));
                   referalActivity.setPostalCode(rs.getString("zip_code"));
                   referalActivity.setSocialSecurityNumber(rs.getString("ssn"));
                   referalActivity.setAccountNumber(rs
                                 .getString("DISP_CNSUMR_ACCT_NUM"));
                   if (rs.getDate("date_processed") != null)
                          referalActivity.setDateSent(rs.getDate("date_processed")
                                          .toString());
                   else
                          referalActivity.setDateSent("");
                   String temp;
                   if (rs.getString("status").equals("2"))
                          referalActivity.setPickedYN("Y");
                   else if (rs.getString("status").equals("1"))
                          referalActivity.setPickedYN("N");
                   
                   System.out.println(referalActivity.toString());
            }
            return rd;
      }


Idealy you should close the resultset, statement and connection before saving the results to the outputstream
0
sunithasAuthor Commented:
hai ,


            I found the solution for my question.....  what i am doing is instead of creating a new node for every row(there are about 50,000 rows) what i am doing is create only one row and write it to outputstream and add keep doing the same....

this way there is only one node in the memory and my prob is solved


0
moduloCommented:
PAQed with points refunded (250)

modulo
Community Support Moderator
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.