JAXB有任何内存问题吗? [英] Are there any memory utlization issue with JAXB?

查看:117
本文介绍了JAXB有任何内存问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JAXB进行xml解析,是否有任何性能或内存利用率问题?

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

推荐答案

要注意的一件事是 JAXBContext.newInstance()是一个非常慢的操作。这是很多反射和类生成的地方,导致duffymo提到的烫发空间问题。值得庆幸的是, JAXBContext 是线程安全的,因此可以缓存一个并重复使用。否则,我认为可以肯定地说JAXB内存使用量将比完整DOM更低(或者更少),当然,还要大于SAX。

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.

如果你有非常大的文件,可以使用JAXB处理它们 JAXB RI发行版包含使用JAXB进行流式传输的示例。

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有任何内存问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆