我有一个 Web 应用程序,其中有从 xsd 架构生成的类。 我正在创建一个 Marshaller 实例和一个 Unmarshaller 实例作为应用程序启动时的静态最终字段。
我想知道这是否是好的做法,或者根据需要创建独立的实例更好?
最佳答案
缓存Marschaller
和Unmarshaller
不是一个好主意。而是缓存 JAXBContext
。
JAXBContext
可以重用来创建编码器和解码器。
Marshaller
和 Unmarshaller
实例(不一定)不是线程安全的或可重用的。
我会查找引用资料并更新答案。
这是reference :
The JAXBContext class is thread safe, but the Marshaller, Unmarshaller, and Validator classes are not thread safe.
相关答案:
关于java - JAXB 每个应用程序一个 Marshaller 实例和 Unmarshaller 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26137226/