JAXB每个应用程序一个Marshaller实例和Unmarshaller实例

时间:2014-10-01 08:31:23

标签: java jaxb

我有web应用程序,我有从xsd schema生成的类。 我正在应用程序启动时创建一个Marshaller实例和一个Unmarshaller实例作为静态最终字段。

我想知道这是否是一种好习惯,还是最好根据需要创建独立实例?

1 个答案:

答案 0 :(得分:4)

缓存MarschallerUnmarshaller不是一个好主意。请改为缓存JAXBContext

JAXBContext可以重复用来创建marshallers和unmarshallers。

MarshallerUnmarshaller个实例不是(必然)线程安全的或可重用的。

我会查找参考资料并更新答案。

这是reference

  

JAXBContext类是线程安全的,但是Marshaller,   Unmarshaller和Validator类不是线程安全的。

相关答案:

JAXB creating context and marshallers cost

相关问题