JAXB创建上下文和marshallers成本 [英] JAXB creating context and marshallers cost

查看:293
本文介绍了JAXB创建上下文和marshallers成本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题有点理论化,创建JAXB上下文,marshaller和unmarshaller的成本是多少?

The question is a bit theoretical, what is the cost of creating JAXB context, marshaller and unmarshaller?

我发现我的代码可以从保持相同的JAXB上下文,可能是所有编组操作的相同编组器,而不是在每个编组时创建上下文和编组器。

I've found that my code could benefit from keeping the same JAXB context and possibly the same marshaller for all marshaling operations rather than creating context and marshaller on each marshaling.

那么创建JAXB上下文和marshaller / unmarshaller的成本是多少?是否可以为每个编组操作创建上下文+编组,或者最好避免它?

So what is the cost of creating JAXB context and marshaller/unmarshaller? Is it okay to create context+marshaller for each marshaling operation or it's better to avoid it?

推荐答案

注意:我是 EclipseLink JAXB(MOXy) 领导和JAXB 2的成员( JSR-222 )专家组。

Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB 2 (JSR-222) expert group.

JAXBContext 是线程安全的,只应创建一次并重复使用以避免成本多次初始化元数据。 Marshaller Unmarshaller 不是线程安全的,但是可以轻量级创建,并且可以按操作创建。

JAXBContext is thread safe and should only be created once and reused to avoid the cost of initializing the metadata multiple times. Marshaller and Unmarshaller are not thread safe, but are lightweight to create and could be created per operation.

这篇关于JAXB创建上下文和marshallers成本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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