my dog learned polymorphism
The moose likes XML and Related Technologies and the fly likes Java.lang.outofmemory error for xml parsing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Java.lang.outofmemory error for xml parsing" Watch "Java.lang.outofmemory error for xml parsing" New topic

Java.lang.outofmemory error for xml parsing

Raje Kumar

Joined: Sep 13, 2004
Posts: 2
I am Parsing an xml document and I am running 4 threads at one time.
I am getting java.lang.outofmemory error. What could be the reason for
this. and how to prevent this from happening.
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
You could either increase the heap size using the -Xmx JVM argument or look into splitting the XML parsing into smaller pieces using SAX, for example.

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13036
1. How large is the XML document? Building a DOM takes many times the size of the original input document since so many objects are involved and the Strings are all Unicode.
2. What are these 4 Threads doing? The parser instance may not be sharable by multiple Threads. For example, see the javax.xml.parsers.DocumentBuilder JavaDocs.
Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
similar questions came up in another forum and if I have some time, I'll give stax (or simply sax) api a try. There are 2 interesting entries in Rickard Obergs weblog about the issue:
I agree. Here's the link:
subject: Java.lang.outofmemory error for xml parsing
It's not a secret anymore!