[jdom-interest] Writing large XML files
Subrahmanian, Sundararaman V [IT]
sundararaman.v.subrahmanian at citigroup.com
Tue May 13 07:10:13 PDT 2003
I have a situation where I have to write a huge file. If all the data that
is to be persisted as XML is converted to XML it might result in more than
10,000 elements. I am pasting here a simple fragment of the code that I am
using to write the XML elements. At some point of time, the program
suddenly aborts without any trace message.
I am using jdom-b8 and jdk version java 1.3.1-b24. I have the following
questions:
1. Should I be writing the elements in smaller chunks? If so, how do I do
it?
2. Will going over to jdom-b9 help? I would not want to do this right now.
3. Also this section gets iterated over several times - is it possible that
the elements created in the previous iteration have not been freed yet by
the garbage collector and hence causing huge memory usage?
Code fragment: (I had put 2 try-catch blocks for debugging purposes)
Element rootElement;
try {
rootElement = new Element(id + m_rootElementSuffix);
Iterator iter = beanMap.keySet().iterator();
while (iter.hasNext()) { // contains more than
10,000 elements
PropertyAccessor propAcc =
(PropertyAccessor)(beanMap.get(iter.next()));
Element element = writeElement(id, propAcc);
// writes the content of propAcc as an XML element
rootElement.addContent(element);
}
} catch (Throwable t) {
LogMgr.info(this, t.getMessage());
throw new RuntimeException("Creating elements: " +
t.getMessage()); // t.getMessage() returns null
}
Writer writer = null;
try {
m_document.setRootElement(rootElement); //
m_document is a class member
m_document.setDocType(docType);
writer = createWriter(id);
// creates a BufferedWriter
m_outputter.output(m_document, writer);
} catch (Throwable t) {
LogMgr.info(this, t.getMessage());
throw new RuntimeException("Writing elements: " +
t.getMessage());
} finally {
try {
if (writer != null) { writer.close(); }
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
}
}
Any help in this regard will be appreciated.
Thanking you,
SVS
More information about the jdom-interest
mailing list