0

I am parsing XML File of Size 2GB. For Parsing am using Xstream Library, Its wait for 5mins then it is throwing java.lang.OutOfMemoryError: GC overhead limit exceeded.

Can you provide solution to parse large amount of XML files. Can you provide alternatives to parse XML Files faster.

Update: I have done using JaxB+Stax parser to resolve performance and resolved java.lang.OutOfMemoryError: GC overhead limit exceeded exception.

Trivikrama
  • 183
  • 1
  • 1
  • 7
  • 2
    Show your code. What are your JVM memory settings? Please read http://stackoverflow.com/help/how-to-ask – reto Aug 17 '15 at 06:30

2 Answers2

1

You should go for a parser whihc wouldn't load the whole xml into memory.

SAX or if you are interested in only a subset of xml then Stax.

Even in those cases , your memory can be clogged up by the data you parse a nd populate into the data structure of your choice.

You should take a look at the below answer How to Parse Big (50 GB) XML Files in Java

Community
  • 1
  • 1
jozzy
  • 2,863
  • 3
  • 15
  • 12
0

You can use SAX parser which doesn't hold whole file in memory and keeps only few things like tags which are not closed yet, in order to catch later errors such as end-tags in the wrong order.

http://docs.oracle.com/javase/7/docs/api/javax/xml/parsers/SAXParser.html

As whole file will not be in memory, it doesn't guarantee the validation of xml file at start. Read more about parser here.

Vimal Bera
  • 10,346
  • 4
  • 25
  • 47
  • SAX is event based. It might be easier to use StAX, which is a pull-parser that also handles large files: https://docs.oracle.com/javase/tutorial/jaxp/stax/index.html – Andreas Aug 17 '15 at 06:43