Is there a problem with memory utilization with JAXB?

I use JAXB to parse xml, are there any problems with performance or memory usage?

+5
source share
6 answers

Remember that this JAXBContext.newInstance()is a very slow operation. There is a lot of thought and class generation going on here, which leads to problems with the spatial space mentioned by duffymo. Fortunately, it JAXBContextis thread safe, so cache and reuse it . Otherwise, I can confidently say that the use of JAXB memory will be at (or maybe less) than the full DOM, and, of course, more SAX.

If you have very large documents, process them in pieces using JAXB . JAXB RI distribution includes an example of streaming with JAXB.

+6
source

JAXB experiences the same basic problems as DOM-based parsing, which, generally speaking, the entire data data structure is stored in memory at the same time. However, it is generally less hungry than the DOM API (with the possible exception of the XOM).

Having said that, there are ways to use JAXB to read fragments of large documents in a streaming manner, if necessary. This is a rather exotic use.

+2
source

, Java XML - / , , .

+2

JAXB , perm . OutOfMemoryError .

+1

, JAXB, "" XML Java, Xerces SAXParser.

0

JVM ( )

-Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true

https://issues.apache.org/jira/browse/CXF-2939

0

All Articles