English 中文(简体)
Are there any memory utlization issue with JAXB?
原标题:
  • 时间:2009-11-16 22:22:16
  •  标签:
  • java
  • xml
  • jaxb

I am using JAXB for xml parsing, are there 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





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签