开发者

Are there any memory utlization issue with JAXB?

I am using JAXB for xml parsing, are the开发者_运维知识库re any performance or memory utilization issues?


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.


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.


You may indeed run into performance and memory issues with Java XML data binding due to excessive object creation/destruction, this article may help explain a new data binding technique that may help avoiding those issues


JAXB has the additional issue of using reflection to create classes that are added to your perm space as it runs. OutOfMemoryError mayhem can ensue.


I have seen that performance can be hit pretty badly with JAXB as opposed to more 'simple' XML handling mechanisms in Java such as the Xerces SAXParser.


Adding below JVM argument can fix this issue (with slight performance impact)

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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜