Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any memory utlization issue with JAXB?

Tags:

java

xml

jaxb

I am using JAXB for xml parsing, are there any performance or memory utilization issues?

like image 523
Venkat Sadasivam Avatar asked Nov 16 '09 22:11

Venkat Sadasivam


2 Answers

One thing to be mindful of is that JAXBContext.newInstance() is a very slow operation. This is where a lot of reflection and class generation happens, leading to perm space issues mentioned by duffymo. Thankfully, JAXBContext is thread-safe, so it's ok to cache one away and reuse it. Otherwise, I think it's safe to say that JAXB memory usage will be on-par (or maybe less) than a full DOM, and, of course, greater than SAX.

If you have very large documents, it's possible to process them in chunks with JAXB. The JAXB RI distribution includes an example of streaming with JAXB.

like image 123
Dave Ray Avatar answered Sep 23 '22 21:09

Dave Ray


JAXB suffers from the same basic issues as DOM-based parsing, which is that generally speaking, the entire data data structure is held in memory at the same time. That said, it's generally less memory-hungry than a DOM API (with the possible exception of XOM).

Having said that, there are ways of using JAXB to read fragments of large documents in a stream-oriented fashion, if needs be. That's fairly exotic usage, though.

like image 25
skaffman Avatar answered Sep 22 '22 21:09

skaffman