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

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

问题描述

这个问题有点理论化,创建 JAXB 上下文、编组器和解组器的成本是多少?

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 上下文和编组/解组的成本是多少?可以为每个编组操作创建上下文+编组器还是最好避免它?

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 是线程安全的,应该只创建一次并重复使用,以避免多次初始化元数据的成本.MarshallerUnmarshaller 不是线程安全的,但创建起来是轻量级的,可以按操作创建.

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 创建上下文和编组器成本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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